本文实例讲述了WordPress给文章图片主动增加链接的办法。分享给大家供大家参考。详细剖析如下:
咱们会看到有很多的网站咱们点击图片就会进入以后文件衔接了,上面我来给应用wordpress博客的同窗也来引见此种办法,图片主动链接到文章,增加题目和ALT属性.
间接将上面的代码增加到主题的 functions.php 文件即可:
function auto_post_link($content) {
global $post;
$content = preg_replace('/<s*imgs+[^>]*?srcs*=s*('|")(.*?)\1[^>]*?/?s*>/i', "<a href="".get_permalink()."" title="".$post->post_title."" ><img src="$2" alt="".$post->post_title."" /></a>", $content);
return $content;
}
add_filter ('the_content', 'auto_post_link',0);
<a href="wordpress-view-history.html" title="WordPress 增加文章阅读历史性能" >
<img src="201303521.png" alt="WordPress 增加文章阅读历史性能" />
</a>
还能够再增加一个性能,将文章标签作为要害词,将文章内的要害词主动加上链接,无利于SEO,他人复制的时分,就会留下链接了,在下面的函数里持续增加一段代码即可:
function auto_post_link($content) {
global $post;
$content = preg_replace('/<s*imgs+[^>]*?srcs*=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);
心愿本文所述对大家的WordPress建站有所协助。
以上就是安达网络工作室关于《WordPress给文章图片自动添加链接的方法》的一些看法。更多内容请查看本栏目更多内容!
本文实例讲述了WordPress制止特定用户修正明码的办法。分享给大家供大家参考。详细办法如下: 有时咱们心愿...
本文实例讲述了WordPress屏蔽评论中链接地址的办法。分享给大家供大家参考。详细剖析如下: 应用WordPress做...
本文实例讲述了wordpress首页不显示指定分类文章的办法。分享给大家供大家参考。详细剖析如下: 有时咱们不...
关于日拜访量还不错的WordPress网站来说,一定都会存在很多待审核的渣滓评论,假如要经过WP后盾删除,那几乎...
很多冤家刚建设博客的时分都是采纳国际优秀的博客零碎:Z-BLOG,用一段工夫当时很多人都想转移到wordpress,...
get_permalink()(获取文章或页面链接) get_permalink() 用来依据固定衔接前往文章或许页面的链接。在获取...