admin管理员组文章数量:1130349
I really can't get the right practices from official docs. I think it's a complete mess.
At some point, they started to say to activate the title-tag feature: after_setup_theme >
add_theme_support('title-tag');
Ok. At this point they stated we should delete the
<title>tag from page and stop usingwp_title(). Perfect.So we had to use the
'wp_title'filter to modify our titles. Right. I did, that worked, once upon a time.Then they said '
'wp_title'filter was deprecated, and we should have usedpre_get_document_titleand other filters. Wow, great. Currently they seem not to work, though.Then they said '
'wp_title'filter was 'reinstated until alternative usages have been identified and a path forward for them defined' Sexy.
But if I look into the core code, I can see that the 'title-tag' has no filters to modify its output. So if I want custom coded texts inside my titles, should I use wp_title() again and disable 'title-tag' support?
Really, can someone shed a definitive light on this topic?
I really can't get the right practices from official docs. I think it's a complete mess.
At some point, they started to say to activate the title-tag feature: after_setup_theme >
add_theme_support('title-tag');
Ok. At this point they stated we should delete the
<title>tag from page and stop usingwp_title(). Perfect.So we had to use the
'wp_title'filter to modify our titles. Right. I did, that worked, once upon a time.Then they said '
'wp_title'filter was deprecated, and we should have usedpre_get_document_titleand other filters. Wow, great. Currently they seem not to work, though.Then they said '
'wp_title'filter was 'reinstated until alternative usages have been identified and a path forward for them defined' Sexy.
But if I look into the core code, I can see that the 'title-tag' has no filters to modify its output. So if I want custom coded texts inside my titles, should I use wp_title() again and disable 'title-tag' support?
Really, can someone shed a definitive light on this topic?
Share Improve this question asked Dec 2, 2019 at 11:16 Luca ReghellinLuca Reghellin 1,6422 gold badges21 silver badges45 bronze badges2 Answers
Reset to default 3Do you have any SEO plugins installed? They usually fiddle with this logic. Having Yoast enabled, the pre_get_document_title does not work for me, instead you should use wpseo_title per their documentation.
Having said that, with SEO plugins disabled and add_theme_support('title-tag'); enabled, the pre_get_document_title filter works for me without any problem.
add_action('after_setup_theme', function () {
add_theme_support('title-tag');
}, 20);
add_filter('pre_get_document_title', function ($title) {
return 'ORO!';
});
Result is, that I see ORO! as the page title.
As far as I can say, currently for me the best option is the old school wp_title() thing: that will work. So:
- Do not add
title-tagtheme sopport - Keep your
<title><?php wp_title([whatever options]) ?></title>on page - If you need further customisations, feel free to use the
wp_titlefilter > it's not deprecated and will correctly work.
Until the next wp messy recommendations..
I really can't get the right practices from official docs. I think it's a complete mess.
At some point, they started to say to activate the title-tag feature: after_setup_theme >
add_theme_support('title-tag');
Ok. At this point they stated we should delete the
<title>tag from page and stop usingwp_title(). Perfect.So we had to use the
'wp_title'filter to modify our titles. Right. I did, that worked, once upon a time.Then they said '
'wp_title'filter was deprecated, and we should have usedpre_get_document_titleand other filters. Wow, great. Currently they seem not to work, though.Then they said '
'wp_title'filter was 'reinstated until alternative usages have been identified and a path forward for them defined' Sexy.
But if I look into the core code, I can see that the 'title-tag' has no filters to modify its output. So if I want custom coded texts inside my titles, should I use wp_title() again and disable 'title-tag' support?
Really, can someone shed a definitive light on this topic?
I really can't get the right practices from official docs. I think it's a complete mess.
At some point, they started to say to activate the title-tag feature: after_setup_theme >
add_theme_support('title-tag');
Ok. At this point they stated we should delete the
<title>tag from page and stop usingwp_title(). Perfect.So we had to use the
'wp_title'filter to modify our titles. Right. I did, that worked, once upon a time.Then they said '
'wp_title'filter was deprecated, and we should have usedpre_get_document_titleand other filters. Wow, great. Currently they seem not to work, though.Then they said '
'wp_title'filter was 'reinstated until alternative usages have been identified and a path forward for them defined' Sexy.
But if I look into the core code, I can see that the 'title-tag' has no filters to modify its output. So if I want custom coded texts inside my titles, should I use wp_title() again and disable 'title-tag' support?
Really, can someone shed a definitive light on this topic?
Share Improve this question asked Dec 2, 2019 at 11:16 Luca ReghellinLuca Reghellin 1,6422 gold badges21 silver badges45 bronze badges2 Answers
Reset to default 3Do you have any SEO plugins installed? They usually fiddle with this logic. Having Yoast enabled, the pre_get_document_title does not work for me, instead you should use wpseo_title per their documentation.
Having said that, with SEO plugins disabled and add_theme_support('title-tag'); enabled, the pre_get_document_title filter works for me without any problem.
add_action('after_setup_theme', function () {
add_theme_support('title-tag');
}, 20);
add_filter('pre_get_document_title', function ($title) {
return 'ORO!';
});
Result is, that I see ORO! as the page title.
As far as I can say, currently for me the best option is the old school wp_title() thing: that will work. So:
- Do not add
title-tagtheme sopport - Keep your
<title><?php wp_title([whatever options]) ?></title>on page - If you need further customisations, feel free to use the
wp_titlefilter > it's not deprecated and will correctly work.
Until the next wp messy recommendations..
本文标签: Html title best practices and usage (wptitletitletag supportetc)
版权声明:本文标题:Html title best practices and usage (wp_title, title-tag support, etc..)? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1744949555a2125898.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论