How do I edit the tag without using the deprecated `wp_title()` function?

It looks like _wp_render_title_tag() method is what outputs the tag, and the source code in 4.8 is available here: https://core.trac.wordpress.org/browser/tags/4.8/src/wp-includes/general-template.php#L1083

You can see:

    echo '<title>' . wp_get_document_title() . '</title>' . "\n";

You could first remove the action from wp_head:

    remove_action( 'wp_head', '_wp_render_title_tag', 1 );

Then add your own title render method:

    add_action( 'wp_head', '_wp_render_title_tag_itemprop', 1 );

    function _wp_render_title_tag_itemprop() {
        if ( did_action( 'wp_head' ) || doing_action( 'wp_head' ) ) {     
            echo '<title itemprop="name">' . wp_get_document_title() . '</title>' . "\n";
        }
    }

Leave a Comment