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
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.
-
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– apoorvCommented Oct 12, 2016 at 13:09
-