批量替换WordPress帖子中的文本的教程

假如经常在WordPress博客文章中添加一些关键短语,但是后面打算将这些关键短语替换为其它内容,手动替换会很麻烦而且工作量大。以下代码段可以帮助非常方便地替换这些关键字。

将以下代码添加到主题的functions.php文件中:

function replace_text_wps($text){
$replace = array(
// '关键词' => '替换的关键词'
'WordPress' => '<a href="URL">wordpress</a>',
'Excel' => '<a href="URL">excel</a>',
'Word' => '<a href="URL">word</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');

👋 感谢您的观看!

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享