最新公告
  • 本站一直秉承服务宗旨:履行“站长”责任,销售只是起点 服务永无止境!”的经营理念立即加入
  • WordPress SEO优化之如何给文章关键词标签自动添加内链

    今天给大家分享一个WordPress SEO优化小技巧,该技巧能够实现文章内的关键词标签自动添加内链。

    内链的好外,自然就不用说了,它可以让百度蜘蛛在你的网站爬行更多的地方。

    当然,很多WordPress插件也可以实现这个功能,但是今天站壳网给大家分享的是不用插件给文章关键词标签自动添加内链的方法。

    那怎么如何让WordPress站点的文章关键词标签自动添加内链呢?其实我们只需要在主题目录下的functiоns.php文件中添加一段代码就可以实现了。

    //WordPress 文章关键词自动内链
    
    functiоn tag_sort($a, $b){
    	if ( $a->name == $b->name ) return 0;
    	return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;
    }
    functiоn tag_link($content){
    	$match_num_from = 1;	//一个标签少于几次不链接
    	$match_num_to = 1;	//一个标签多链接几次
    	$posttags = get_the_tags();
    	if ($posttags) {
    		usort($posttags, \"tag_sort\");
    		foreach($posttags as $tag) {
    			$link = get_tag_link($tag->term_id);
    			$keyword = $tag->name;
    			//链接代码
    			$cleankeyword = stripslashes($keyword);
    			$url = \"<a href=\\\"$link\\\" title=\\\"\".str_replace(\'%s\',addcslashes($cleankeyword, \'$\'),__(\'更多关于 %s 的文章\')).\"\\\"\";
    			$url .= \' target=\"_blank\"\';
    			$url .= \">\".addcslashes($cleankeyword, \'$\').\"</a>\";
    			$limit = rand($match_num_from,$match_num_to);
    			//不链接代码
    			$content = preg_replace( \'|(<a[^>]+>)(.*)<pre.*?>(\'.$ex_word.\')(.*)<\\/pre>(</a[^>]*>)|U\'.$case, \'$1$2%&&&&&%$4$5\', $content);
    			$content = preg_replace( \'|(<img)(.*?)(\'.$ex_word.\')(.*?)(>)|U\'.$case, \'$1$2%&&&&&%$4$5\', $content);
    			$cleankeyword = preg_quote($cleankeyword,\'\\\'\');
    			$regEx = \'\\\'(?!((<.*?)|(<a.*?)))(\'. $cleankeyword . \')(?!(([^<>]*?)>)|([^>]*?</a>))\\\'s\' . $case;
    			$content = preg_replace($regEx,$url,$content,$limit);
    			$content = str_replace( \'%&&&&&%\', stripslashes($ex_word), $content);
    		}
    	}
    	return $content;
    }
    add_filter(\'the_content\',\'tag_link\',1);
    

     

    1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
    2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
    3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
    4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
    5. 如有链接无法下载、失效或广告,请联系管理员处理!
    6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
    7. 如有侵权麻烦联系邮箱2697381891@qq.com删除文章!

    源码库 » WordPress SEO优化之如何给文章关键词标签自动添加内链
    • 3047会员总数(位)
    • 37766资源总数(个)
    • 0本周发布(个)
    • 0 今日发布(个)
    • 1199稳定运行(天)

    提供最优质的资源集合

    立即查看 了解详情