本文实例讲述了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给文章图片自动添加链接的方法》的一些看法。更多内容请查看本栏目更多内容!
Hana Flv Player 是一个在 WordPress 中使用比拟宽泛的播放器插件, 该插件内置了5种媒体播放器,其播放文件...
前言 家喻户晓WordPress默许支持大局部图片等文件格局的上传,但也有一些文件格局是不支持的,依据集体需求...
自己2012年12月20日左右接触wordpress,至今曾经两个月。由于以前丝毫没有网站治理经历及编程才能,因而...
本文实例讲述了制止WordPress主动交换半角标点符号的办法。分享给大家供大家参考。详细剖析如下: 用wordpr...
博客吧转载了零号相册的Wordpress博客自带嵌套回复教程。 自带嵌套性能工作原理: wordpress嵌套回复的工作...
目前.htaccess 文件的次要成绩是RewriteCond 指令性地反省磁盘文件能否存在,就算基本不需求反省,每一次拜...