如何给wordpress文章中的图片自动添加图片链接地址呢?
这里我们只需要在主题中的funtion.php文件中加入如下代码即可。
/*
==================================================
wordpress图片自动添加链接
==================================================
*/
add_filter('the_content', 'fancybox1');
add_filter('the_content', 'fancybox2');
function fancybox1($content){
global $post;
$pattern = "/<img(.*?)src=('|\")([^>]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 data-fancybox="images"><img$1src=$2$3.$4$5$6></a>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
function fancybox2($content){
global $post;
$pattern = "/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>(.*?)<\/a>/i";
$replacement = '<a$1href=$2$3.$4$5 data-fancybox="images"$6>$7</a>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
此段代码来自“【WordPress教程】给文章页增加图片Fancybox灯箱效果/支持放大自动播放等”中的一部分。
上面自动添加灯箱教程,在添加了外链转内链功能的wordpress站点无效。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容