簡體   English   中英

更改Wordpress博客文章標題

[英]Changing Wordpress blog post title

我想更改博客文章的標題。 我無法在主題中做到這一點。 它需要使用過濾器來完成。

我已在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;
}

嘗試使用此代碼或將您的priority提高到更大

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

您將priority提高

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM