admin管理员组文章数量:1391929
The below function wraps all titles of all pages in a * symbol. I want to change the function so that it only applies the filter to titles of single posts. How can I accomplish this?
function apply_titles($title, $id) {
return "* ".$title." *";
return $title;
}
add_filter('the_title', 'apply_titles', 10, 2);
The below function wraps all titles of all pages in a * symbol. I want to change the function so that it only applies the filter to titles of single posts. How can I accomplish this?
function apply_titles($title, $id) {
return "* ".$title." *";
return $title;
}
add_filter('the_title', 'apply_titles', 10, 2);
Share
Improve this question
asked Mar 16, 2020 at 7:57
A BanitabaA Banitaba
31 bronze badge
1 Answer
Reset to default 0If you want to wrap post title of posts only, then you should use get_post_type()
to check post type of post. You can take reference from below code, it will applied on "post" post type only. and want to apply on post single page then you have to add is_single()
with get_post_type()
condition.
function apply_titles($title, $id) {
if('post' == get_post_type($id) && is_single())
{
return "* ".$title." *";
}
return $title;
}
add_filter('the_title', 'apply_titles', 10, 2);
本文标签: functionsonly update titles of single posts
版权声明:本文标题:functions - only update titles of single posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744665922a2618530.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论