2

i'm using wordpress 4.6 i'd like to remove just the title tag automatically outputted by wordpress because need to hardcode the html title tag in the template.

i guess is something like this:

add_action('wp_head', '//remove title tag command');

but i didn't find any valid solution so far.

4 Answers 4

10

You can see everything added to wp_head in the file /wp-includes/default-filters.php.

If your theme supports the title tag, you can remove it entirely with remove_action:

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

Though it may be simpler/better to use remove_theme_support( 'title-tag' ) in a child theme, which is what _wp_render_title_tag checks before outputting the title tag.

0
2

Wordpress 5.7.1 with Yoast SEO installed Working code is:

add_filter('document_title_parts', '__return_empty_array', 10);
0
if ( is_page('138') )
{
      add_filter( 'the_title', '__return_false' );
}

add_filter('wp_head', function () {
    if (!current_theme_supports('title-tag')) {
        return;
    }

    if (did_action('wp_head') || doing_action('wp_head') && is_single()) {
        $categories = get_the_category();
        // Assuming the post has many categories will take the first
        $category = reset($categories);

        if ($category) {
            echo '<title>' . $category->name . ' - ' . get_the_title() . '</title>' . "\n";
        }
    }
    echo '<title>' . wp_get_document_title() . '</title>' . "\n";
});
1
  • Please edit your answer, and add an explanation: why could that solve the problem?
    – fuxia
    Mar 26 at 11:07
0
add_filter( 'pre_get_document_title' , 'render_title' );
function render_title($title){
    return 'New title ';
}
add_filter(  'document_title_parts' , 'render_title' );
function render_title($parts){
    $parts["title"] = "My Prefix ". $parts["title"];
    return $parts;
}
1
  • Please edit your answer, and add an explanation: why could that solve the problem?
    – fuxia
    Mar 26 at 11:08

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