【问题标题】:How remove or change <title> tag in wordpress using plugin , add_filter ?如何使用插件 add_filter 在 wordpress 中删除或更改 <title> 标签?
【发布时间】:2011-11-12 23:07:08
【问题描述】:

我需要使用插件更改或删除 wordpress 中的 &lt;title&gt; 标签
例如&lt;title&gt; My old title &lt;/title&gt; => &lt;title&gt; New title &lt;/title&gt;

我试试

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

add_filter('wp_head','plugin_title');

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

【问题讨论】:

  • 不是真的,这是 Wordpress 特有的。
  • @cbuckley 只要是和HTML解析有关的,转换DomDocument不是那么难
  • @ajreal:不。这与 Wordpress 如何实现插件有很大关系。

标签: php wordpress plugins title add-filter


【解决方案1】:

尝试使用 wp_title 钩子

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

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

【讨论】:

    猜你喜欢
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多