【问题标题】:Changing Wordpress blog post title更改 Wordpress 博客文章标题
【发布时间】:2015-10-05 13:14:00
【问题描述】:

我想更改我博客文章的标题。我不能在主题中这样做。需要通过过滤器来完成。

我在我的 Wordpress 博客上使用的主题中的 functions.php 中添加了以下代码:

function overwrite_post_title($title, $sep) {
    //global $post;
    //if ( is_single($post->ID) && !is_attachment($post->ID) )
    //if ( is_single() && !is_attachment() )

    var_dump($title);

    $title = "Test";

    return $title;
}
add_filter('wp_title', 'overwrite_post_title', 10, 2);

它应该更改帖子的标题。 但它什么也没做。它甚至没有被执行。

【问题讨论】:

  • 对我来说很好。你把这段代码放在哪里了?

标签: php wordpress title


【解决方案1】:

尝试此代码或将您的priority 增加到较大的值

function overwrite_post_title($title="", $sep="") {
    $title = "Test";
    return $title;
}
add_filter('wp_title', 'overwrite_post_title', 10, 2);

你增加priority by

add_filter('wp_title', 'overwrite_post_title', 1, 2);

【讨论】:

    【解决方案2】:

    尝试使用这个

    add_filter( 'the_title', 'ta_modified_post_title');
    function ta_modified_post_title ($title) {
      if ( in_the_loop() && !is_page() ) {
        $title = "Test (modified title)"; // your title name
      }
      return $title;
    }
    

    【讨论】:

      猜你喜欢
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多