admin管理员组文章数量:1130349
For example, the site has a category "News", in which there are 37 posts num.
How to insert into wp_title the number of records (37) in this category.
those, if we go to the "News" category, the title should be displayed:
<title>37 posts in News category | Site name</title>
Help me please, Regards, Anna
For example, the site has a category "News", in which there are 37 posts num.
How to insert into wp_title the number of records (37) in this category.
those, if we go to the "News" category, the title should be displayed:
<title>37 posts in News category | Site name</title>
Help me please, Regards, Anna
Share Improve this question asked Dec 18, 2018 at 6:29 AnnaAnna 335 bronze badges1 Answer
Reset to default 4If your theme supports WordPress adding the title tag using add_theme_support( 'title-tag' ); (it should!) you can use the document_title_parts filter to insert the post count in the right place without needing to parse the full title or modify existing elements that might have been customised, such as the separator:
function wpse_323260_document_title_category_count( $title ) {
if ( is_category() ) {
$category = get_queried_object();
$title['title'] = sprintf(
'%d posts in %s Category',
$category->count,
esc_html( single_cat_title( '', false ) )
);
}
return $title;
}
add_filter( 'document_title_parts', 'wpse_323260_document_title_category_count' );
For example, the site has a category "News", in which there are 37 posts num.
How to insert into wp_title the number of records (37) in this category.
those, if we go to the "News" category, the title should be displayed:
<title>37 posts in News category | Site name</title>
Help me please, Regards, Anna
For example, the site has a category "News", in which there are 37 posts num.
How to insert into wp_title the number of records (37) in this category.
those, if we go to the "News" category, the title should be displayed:
<title>37 posts in News category | Site name</title>
Help me please, Regards, Anna
Share Improve this question asked Dec 18, 2018 at 6:29 AnnaAnna 335 bronze badges1 Answer
Reset to default 4If your theme supports WordPress adding the title tag using add_theme_support( 'title-tag' ); (it should!) you can use the document_title_parts filter to insert the post count in the right place without needing to parse the full title or modify existing elements that might have been customised, such as the separator:
function wpse_323260_document_title_category_count( $title ) {
if ( is_category() ) {
$category = get_queried_object();
$title['title'] = sprintf(
'%d posts in %s Category',
$category->count,
esc_html( single_cat_title( '', false ) )
);
}
return $title;
}
add_filter( 'document_title_parts', 'wpse_323260_document_title_category_count' );
本文标签: wp titleHow to insert the number of posts from the category in wp title
版权声明:本文标题:wp title - How to insert the number of posts from the category in wp _title? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749088628a2314169.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论