我試圖創建一個函數,當它的保存(the_content)時對文章內容進行文本替換。如何使用str_ireplace()在發佈/保存例程期間過濾帖子內容?
存根函數在下面,但是如何獲得對發佈內容的引用,然後將過濾的內容返回到「publish_post」例程?
但是,我的替換要麼不工作和/或不傳遞更新post_content發佈功能。值不會被替換。
function my_function() {
global $post;
$the_content = $post->post_content;
$text = " test ";
$post->post_content = str_ireplace($text, '<b>'.$text.'</b>', $the_content );
return $post->post_content;
}
add_action('publish_post', 'my_function');
感謝小屋。看起來不錯,但是當我測試它時,點擊帖子編輯器上的「更新」後內容保持不變。我想用粗體替換替換「測試」一詞的所有實例... – 2010-10-28 15:29:54