0

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";
            }
        }
} 
2

1 Answer 1

1

Thanks 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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.