admin管理员组文章数量:1427340
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.
本文标签: filtersAdd PHP code after title in single post pages
版权声明:本文标题:filters - Add PHP code after title in single post pages? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745495629a2660793.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
the_title
hook. – Mayeenul Islam Commented Oct 19, 2015 at 8:00