WordPress SEO技巧 – 为关键词自动添加超链接 - 任刚 · Ren Gang - 我的设计笔记 世界设计 · 设计世界

WordPress SEO技巧之 – 为关键词自动添加超链接,只要在主题的function.php里添加如下代码:

function auto_post_link($content) {
		global $post;
        $content = preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', "<a href=\"".get_permalink()."\" title=\"".$post->post_title."\" ><img src=\"$2\" alt=\"".$post->post_title."\" /></a>", $content);
 
	    $posttags = get_the_tags();
	 if ($posttags) {
		 foreach($posttags as $tag) {
			 $link = get_tag_link($tag->term_id); 
			 $keyword = $tag->name;
	   		$content = preg_replace('\'(?!((<.*?)|(<a.*?)))('. $keyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s','<a href="'.$link.'" title="'.$keyword.'">'.$keyword.'</a>',$content,2);//最多替换2个重复的词,避免过度SEO
		 }
	 }
	   return $content;
}
add_filter ('the_content', 'auto_post_link',0);
" /> 超链接 · 任刚 · Ren Gang - 我的设计笔记

超链接    106

WordPress SEO技巧 – 为关键词自动添加超链接

小贴士      

登 录 注 册