本文整理自网络,侵删。
本文实例讲述了WordPress给文章图片自动添加链接的方法。分享给大家供大家参考。具体分析如下:
我们会看到有很多的网站我们点击图片就会进入当前文件连接了,下面我来给使用wordpress博客的同学也来介绍此种方法,图片自动链接到文章,添加标题和ALT属性.
直接将下面的代码添加到主题的 functions.php 文件即可:
代码如下:
function auto_post_link($content) {
global $post;
$content = preg_replace('/<s*imgs+[^>]*?srcs*=s*('|")(.*?)\1[^>]*?/?s*>/i', "<a .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);
最终的输出结果如下:
global $post;
$content = preg_replace('/<s*imgs+[^>]*?srcs*=s*('|")(.*?)\1[^>]*?/?s*>/i', "<a .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 title="WordPress 添加文章浏览历史功能" >
<img src="201303521.png" alt="WordPress 添加文章浏览历史功能" />
</a>
关键词自动添加链接
<img src="201303521.png" alt="WordPress 添加文章浏览历史功能" />
</a>
关键词自动添加链接
相关阅读 >>
wordpress中is_sticky()判断文章是否置顶的参数与用法
wordpress 相册插件 nextgen-gallery 添加目录将中文转为拼音的解决办法
wordpress wp_head()函数使页面顶部总空白28px
更多相关阅读请进入《wordpress》频道 >>
相关推荐
评论
管理员已关闭评论功能...
- 欢迎访问木庄网络博客
- 可复制:代码框内的文字。
- 方法:Ctrl+C。