Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How remove or change <title> tag in wordpress using plugin , add_filter ?

I need change or remove <title> tag in wordpress using plugin
for example <title> My old title </title> => <title> New title </title>

I try it

function plugin_title($content){
    $content=str_replace('My old title','New title',$content); 
    return $content;
}

add_filter('wp_head','plugin_title');

// but it doesn't work . Any idea ?

like image 887
Darek Rycyk Avatar asked Feb 24 '23 01:02

Darek Rycyk


1 Answers

Try using the wp_title hook

add_filter( 'wp_title', 'custom_title', 20 );

function custom_title( $title ) {
    return str_replace('My old title', 'New title', $title); 
}
like image 57
Mark Avatar answered May 08 '23 07:05

Mark