I tried to add PHP code after the post title in single post pages by adding a filter to functions.php
, but this did not work:
function theme_slug_filter_the_content( $content ) {
$custom_content = 'MY CODES';
$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'theme_slug_filter_the_content' );
I tried to add PHP code after the post title in single post pages by adding a filter to functions.php
, but this did not work:
function theme_slug_filter_the_content( $content ) {
$custom_content = 'MY CODES';
$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'theme_slug_filter_the_content' );
Share
Improve this question
edited Oct 19, 2015 at 14:21
Gabriel
2,24810 gold badges22 silver badges24 bronze badges
asked Oct 19, 2015 at 6:14
AminAmin
11 bronze badge
1
|
2 Answers
Reset to default 1You need to use the_title
filter, not the_content
.
Also make sure you have the_title()
function somewhere in your single post page.
Here is the code:
function theme_slug_filter_the_content( $title ) {
$custom_title = 'MY CODES';
$custom_title .= $title ;
return $custom_title ;
}
add_filter( 'the_title', 'theme_slug_filter_the_content' );
See the below code that you needs to write in content.php file
if ( is_single() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );
endif;
Here after Or you can add your code.
I hope your single.php file load template function call this content.php file. you can check this on twentyfifteen theme also that comes with default wordpress installation.
the_title
hook. – Mayeenul Islam Commented Oct 19, 2015 at 8:00