网站系统教程
WordPress教程:替换文章的某些文字
来源:     阅读:352
源码网
发布于 2021-12-12 10:46
查看主页

有时候我们需要替换文章的某些文字为其它文字,比如给特定的文字加上链接,利用 SEO 和用户体验。

下边的代码即可实现这种功能:

/**

    *WordPress 替换文章的某些文字

    *https://www.adminbuy.cn/

*/

function Bing_content_str_replace($text){

    $replace_words = array(

        //添加要替换的文本,格式:'要替换的' => '替换到的内容'

        'adminbuy' => '<a href="http://www.adminbuy.cn">adminbuy.cn</a>',

        '魔客吧' => '<a href="http://www.adminbuy.cn">AB模版网</a>',

        'functions.php' => '<a href="https://www.adminbuy.cn/wordpress/">functions.php</a>'

    );

    return str_replace( array_keys( $replace_words ), $replace_words, $text );

}

add_filter( 'the_content', 'Bing_content_str_replace' );

add_filter( 'the_excerpt', 'Bing_content_str_replace' );


免责声明:本文为用户发表,不代表网站立场,仅供参考,不构成引导等用途。 网站系统教程 wordpress教程
相关推荐
PbootCMS多选按钮前台页面如何循环|内容多选遍历
PbootCMS网站转移后无法打开报错提示“No input file specifed”
PbootCms兼容模式下微信分享网址无法访问修复方法
PbootCms缩略图裁剪优化居中裁剪(直接上干货)
ecshop的SEO优化有什么好的建议