Php 更改Wordpress博客文章标题

Php 更改Wordpress博客文章标题,php,wordpress,title,Php,Wordpress,Title,我想更改我博客文章的标题。我不能在主题中这样做。这需要一个过滤器来完成 我已将以下代码添加到Wordpress博客主题中的functions.php中: function overwrite_post_title($title, $sep) { //global $post; //if ( is_single($post->ID) && !is_attachment($post->ID) ) //if ( is_single() &&a

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

我已将以下代码添加到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);
它应该改变一篇文章的标题。 但它什么也没做。它甚至没有被执行。

尝试使用此选项

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;
}

尝试此代码或将
优先级
提高到较大值

function overwrite_post_title($title="", $sep="") {
    $title = "Test";
    return $title;
}
add_filter('wp_title', 'overwrite_post_title', 10, 2);
您可以将
优先级增加

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

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