我爱水煮鱼 » WordPress » WordPress 技巧:如何快速替换日志中的文本

WordPress 技巧:如何快速替换日志中的文本

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 插件进行操作。

标签:

分享到:

请选择你看完该文章的感受:

不错 超赞 无聊 扯谈 不解 路过
  1. 不是很明白其中的道理
    请问:这段代码的意思是“在文章页将某些特定的关键字替代成带有链接的关键字”
    是这样吗?

    比如说文章中含有wordpress,那么这段代码就是将wordpress加上一个特定的链接

    请问:我的理解对吗?