admin管理员组文章数量:1122832
This code adds the image before all titles on the page.
How do i add one single image before the posts entry title?
function adt_abovetitle($title){
//Return new title if called inside loop
if ( in_the_loop() ) {
$x = do_shortcode('[shortcode id="'. $id . '"]');
return $x . $title;
} else {
//Else return regular
return $title;
}
}
add_filter( 'the_title', 'adt_abovetitle');
This code adds the image before all titles on the page.
How do i add one single image before the posts entry title?
function adt_abovetitle($title){
//Return new title if called inside loop
if ( in_the_loop() ) {
$x = do_shortcode('[shortcode id="'. $id . '"]');
return $x . $title;
} else {
//Else return regular
return $title;
}
}
add_filter( 'the_title', 'adt_abovetitle');
Share
Improve this question
edited Feb 4, 2015 at 16:29
Brad Dalton
6,9672 gold badges36 silver badges47 bronze badges
asked Feb 4, 2015 at 15:42
AriAri
1,1971 gold badge17 silver badges28 bronze badges
2 Answers
Reset to default 0This works fine for me when i test it. I did edit your code as you had a small error in the function name not matching.
Also, you might want to add a conditional tag and wrap the shortcode in a div but otherwise it works.
function adt_abovetitle($title){
//Return new title if called inside loop
if ( in_the_loop() && is_singular('post') ) {
$x = do_shortcode('[shortcode id="'. $id . '"]');
return $x . $title;
} else {
//Else return regular
return $title;
}
}
add_filter( 'the_title', 'adt_abovetitle');
You might want to test your else statement as well.
The in_the_loop()
and is_singular()
functions are too heavy and slow down the page load. You just need to edit single.php
file in your theme root folder.
The code will look like this:
if (has_post_thumbnail()) {
the_post_thumbnail('full');
}
<h1 class="entry-title"><?php the_title(); ?></h1>
本文标签: Add Image Before Posts Entry Title
版权声明:本文标题:Add Image Before Posts Entry Title 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736286572a1927694.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论