admin管理员组文章数量:1312662
I want to conditionally prefix the contents of the tag if the IP address matches the dev server. I cobbled something together, and it will output the title tag correctly, but the original title tag precedes it, and therefore is the content shown in the browser tab. Thoughts?
$host = $_SERVER['SERVER_ADDR'];
if ($host =='0.0.0.0') {
remove_action( 'wp_head', '_wp_render_title_tag', 1 );
add_action( 'wp_head', '_wp_render_title_tag_dev', 1 );
function _wp_render_title_tag_dev() {
if ( did_action( 'wp_head' ) || doing_action( 'wp_head' ) ) {
echo '<title>DEV SRV:' . wp_get_document_title() . '</title>' . "\n";
}
}
}
I want to conditionally prefix the contents of the tag if the IP address matches the dev server. I cobbled something together, and it will output the title tag correctly, but the original title tag precedes it, and therefore is the content shown in the browser tab. Thoughts?
$host = $_SERVER['SERVER_ADDR'];
if ($host =='0.0.0.0') {
remove_action( 'wp_head', '_wp_render_title_tag', 1 );
add_action( 'wp_head', '_wp_render_title_tag_dev', 1 );
function _wp_render_title_tag_dev() {
if ( did_action( 'wp_head' ) || doing_action( 'wp_head' ) ) {
echo '<title>DEV SRV:' . wp_get_document_title() . '</title>' . "\n";
}
}
}
Share
Improve this question
asked Dec 16, 2020 at 18:39
whakawaeherewhakawaehere
7910 bronze badges
2
- 1 Why not use the filter? developer.wordpress/reference/hooks/wp_title – shanebp Commented Dec 16, 2020 at 19:21
- @shanebp because when I work alone, I overthink and often overcomplicate things. Thanks. Solved. – whakawaehere Commented Dec 16, 2020 at 20:59
1 Answer
Reset to default 1Thanks to @shanebp for reminding me to simplify
add_filter('wp_title', 'dev_srv_title');
function dev_srv_title($title) {
$host = $_SERVER['SERVER_ADDR'];
if ($host =='0.0.0.0') {
return 'DEV SRV: '.$title;
}
return $title;
}
本文标签: wp headPrefix the title tagif IP address is the dev server
版权声明:本文标题:wp head - Prefix the title tag, if IP address is the dev server 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741913042a2404559.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论