• Resolved Jacorre

    (@jacorre)


    Hi everyone,

    I’m using a shortcode like the following:

    function my_content( $atts, $content = null ) {
    return '<div id="content">' . do_shortcode($content) . '</div>';
    }
    add_shortcode('content', 'my_content');

    My question is if it’s possible to only apply this shortcode to a specific template page? For example, single-book.php?

    So the shortcode would only be used for the custom post type of book and it would not apply to all other areas of the site where the_content() is used.

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter Jacorre

    (@jacorre)

    Nevermind, I answered my own question after thinking more about it!

    I used the following:

    function my_content( $atts, $content = null ) {
     if ('book' == get_post_type && is_single()) {
       return '<div id="content">' . do_shortcode($content) . '</div>';
     }
    }
    add_shortcode('content', 'my_content');
Viewing 1 replies (of 1 total)
  • The topic ‘Shortcode to only apply to content on single-post-type page?’ is closed to new replies.