有時候你需要把一篇文章設成密碼保護狀態, 在WordPress里這是件很容易的事,你只要在“發布”按鈕上方對文章的“公開度”下選擇“密碼保護”或者“私人的”就可以了。 但是在默認情況下,當你輸入某篇文章的密碼前后,WordPress都會顯示“這是一篇受保護的文章”字樣。 有沒有辦法隱藏文章標題上的“受保護”或者“私人”標記呢?
WordPress官方論壇上的這段代碼或許可以幫你解決這個問題:
function the_title_trim($title) {
$title = attribute_escape($title);
$findthese = array(
'#Protected:#',
'#Private:#'
);
$replacewith = array(
'', // What to replace "Protected:" with
'' // What to replace "Private:" with
);
$title = preg_replace($findthese, $replacewith, $title);
return $title;
}
add_filter('the_title', 'the_title_trim');
一些插件也能達到同樣的效果,不過我想還是直接把代碼貼到functions.php更快更方便。
來源:Remove Private/Protected from Post Titles