0

Hello guys I am creating a plugin in which I am making a custom post type season. Now I would like to echo something on season single page based on a database query. I have query and logics figured out but I want to echo on season single page from plugin file only not creating a single template and then use filter like post type template. If you could only show echo 'hello world'; on only post_type="season" that would be great. Thanks.

1 Answer 1

0

You could do this with the the_content filter:

/**
 * Adds some text to bottom of the content on 'season' pages.
 *
 * @param   string  $content    The current content of the season page.
 * @return  string              The new content of the season page.
 */
function add_season_content( $content ) {

    if ( is_singular( 'season' ) && is_main_query() ) {

        // collect your season data over here...
        $season_data = 'Hello world';

        $content .= $season_data;
    }

    return $content;

}

add_filter( 'the_content', 'add_season_content' );

Place this code anywhere inside your plugin files.

2
  • Thanks Jhu I figured it would be the_content filter but my code was not working. Yours worked like a charm. Thank you for taking time and answering
    – apoorv
    Commented Oct 12, 2016 at 13:09
  • Cool! Would you mind marking it as the right answer? Commented Oct 13, 2016 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.