Prefix the title tag, if IP address is the dev server
Question
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";
}
}
}
0
2 years
2020-12-16T13:10:22-05:00
2020-12-16T13:10:22-05:00 0 Answers
7 views
0
Leave an answer