首页 Wordpress WordPress 自动内链关键词

WordPress 自动内链关键词

有时,我们想有利于SEO的情况下,将博客内文章所有有关博客的关键词都进行内链,如果自己一个一个手动修改的话比较麻烦,可以通过以下代码批量自动内链关键词。
php
/* 文章指定关键词添加内链开始 */
function replace_text_wps($text){
	$replace = array(
			'微言心语' => '<a href="http://wuean.com/" target="_blank" title="微言心语的博客" rel="noopener">微言心语</a>',
			'GavinWu' => '<a href="http://wuean.com/" target="_blank" title="GavinWu发布的文章" rel="noopener">GavinWu</a>',
			'Wordpress' => '<a href="http://wuean.com/category/wordpress" target="_blank" title="Wordpress相关内容" rel="noopener">Wordpress</a>',
	);
	$text = str_replace(array_keys($replace), $replace, $text);
	return $text;
}
add_filter( 'the_content', 'replace_text_wps');
演示: 特别要注意这种方法对于英文比较呆板,能精确到大小写。什么意思呢,就像上面代码中的Wordpress,如果的文章中wordpress的W不是大写他是不会链接的。

相关推荐

发表回复

邮箱地址不会被公开。