我創建了一個過濾器,修改post_title(),但我遇到的問題是,它正在修改the_title()的每個實例。我用in_the_loop()函數解決了大部分問題,但是任何在循環中有「next post」「previous post」導航鏈接的主題仍然應用了過濾器(可以這麼理解)。我如何才能將過濾器應用於當前帖子的the_title()?你怎麼add_filter只有一個實例的the_title()
function xyz_the_title($the_title) {
if(!in_the_loop())
return $the_title;
$location = get_post_meta(get_the_ID(), 'location', true);
$the_title .= ' - ' . $location;
return $the_title;
}
add_filter('the_title', 'xyz_the_title');
我以爲你只是試圖影響「the_title」,正確的最頂端實例? –
這是正確的。如果你把這個網頁作爲一個例子http://twentythirteendemo.wordpress.com/2013/02/11/popular-science/,文本「大衆科學」是我想改變的。我的代碼也正在改變我不想改變的底部附近的「怪物引擎」文本。 – CCCP
如果是這樣,使用過濾器不是一個正確的方法。您應該在輸出標題的地方自定義您的主題。 – s976