WordPress教程:替换文章的某些文字

2016-04-14 0 358
 
有时候我们需要替换文章的某些文字为其它文字,比如给特定的文字加上链接,利用 SEO 和用户体验。
下边的代码即可实现这种功能:
/**
    *WordPress 替换文章的某些文字
    */
*/
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="/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' );
收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

整合全网资源下载 wordpress教程 WordPress教程:替换文章的某些文字 https://www.xliem.com/1134.html

常见问题

相关文章

官方客服团队

为您解决烦忧 - 24小时在线 专业服务