WordPress教程:替换文章的某些文字
- 2019年11月29日
- beetheme.cn
- 未收录
- 21
(window.slotbydup = window.slotbydup || []).push({
id: "u6201117",
container: "_loc2j2sosji",
async: true
});
有时候我们需要替换文章的某些文字为其它文字,比如给特定的文字加上链接,利用 SEO 和用户体验。
下边的代码即可实现这种功能:
/**
*WordPress 替换文章的某些文字
*https://www.beetheme.cn/
*/
function Bing_content_str_replace($text){
$replace_words = array(
//添加要替换的文本,格式:'要替换的' => '替换到的内容'
'beetheme' => '<a href="https://www.beetheme.cn">beetheme.cn</a>',
'#beetheme资源网#' => '<a href="https://www.beetheme.cn">#beetheme资源网#</a>',
'functions.php' => '<a href="https://www.beetheme.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 / DedeCMS / ThinkPHP 等
系统建站、仿站、开发、定制等业务!
1. 本站所有资源来源于用户上传和网络,仅作为演示数据,如有侵权请邮件联系站长!
2. 本站承接各类网站建设,仿站,多平台小程序搭建制作!
3. 本站联系QQ:897918909
beetheme资源网 » WordPress教程:替换文章的某些文字
2. 本站承接各类网站建设,仿站,多平台小程序搭建制作!
3. 本站联系QQ:897918909
beetheme资源网 » WordPress教程:替换文章的某些文字