首页 文章

如何使用插件add_filter删除或更改wordpress中的<title>标签?

提问于
浏览
4

我需要使用插件更改或删除wordpress中的 <title> 标记
例如 <title> My old title </title> => <title> New title </title>

我试试看

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

add_filter('wp_head','plugin_title');

//但它不起作用 . 任何的想法 ?

1 回答

  • 8

    尝试使用wp_title钩子

    add_filter( 'wp_title', 'custom_title', 20 );
    
    function custom_title( $title ) {
        return str_replace('My old title', 'New title', $title); 
    }
    

相关问题