WordPress 技巧:如何快速替换日志中的文本,把下面的代码放到当前主题的 functions.php 文件中,然后在第四行需要替换的文本改成你的:
function replace_text_wps($text){
$replace = array(
// 'WORD TO REPLACE' => 'REPLACE WORD WITH THIS'
'wordpress' => '<a href="#">wordpress</a>',
'excerpt' => '<a href="#">excerpt</a>',
'function' => '<a href="#">function</a>'
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
add_filter('the_content', 'replace_text_wps');
add_filter('the_excerpt', 'replace_text_wps');
如果你需要永久替换的话,建议使用 Search & Replace 插件进行操作。

不是很明白其中的道理
请问:这段代码的意思是“在文章页将某些特定的关键字替代成带有链接的关键字”
是这样吗?
比如说文章中含有wordpress,那么这段代码就是将wordpress加上一个特定的链接
请问:我的理解对吗?
囧。。。。。
不是,这是一个例子,是吧 WordPres 这个文本替换成 带链接的 wordpress 文本。
嘿嘿,表示感谢,对了,这段代码和WP Keyword Link插件相比,哪个更好一点儿呢?
strtr的效率远高于str_replace