WordPress文章图片换灯箱(无效)

第一步和第二部的js,css文件,wordpress 都有
https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css?ver=6.6.2
https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js?ver=6.6.2

footer.php 和 header.php 可以不用添加script、link
图片幻灯箱失效原因,应该是functions.php的add_filter方法

下面的方法已失效

footer.php

<!--图片灯箱效果-->
<script src="  
https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js?ver=6.6.2"></script>

header.php

<!--图片灯箱效果-->
<link rel="stylesheet" href="  
https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css?ver=6.6.2" />

functions.php


//图片灯箱效果
add_filter('the_content', 'fancybox');function fancybox($content){$pattern = array("/<img(.*?)src=('|\")([^>]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>/i","/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>(.*?)<\/a>/i");$replacement = array('<a$1href=$2$3.$4$5 data-fancybox="gallery"><img$1src=$2$3.$4$5$6></a>','<a$1href=$2$3.$4$5 data-fancybox="images"></a>');$content = preg_replace($pattern, $replacement, $content);return $content;}



知识共享许可协议本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。

相关推荐

Wordpress 添加外链go跳转页面

添加这个功能的主要目的是网站外链有可能会影响自己的博客权重,部分外链还可能存在风险。 所以添加这个go跳转页面 ...

暂无评论

目录展开