给你的wordpress添加文章内图片鼠标点击放大浏览的功能吧~

靠谱杨 2022-7-18 446 7/18

给你的wordpress添加文章内图片鼠标点击放大浏览的功能吧~

注:笔者已启用WP Githuber MD插件使用Markdown语法进行文章编辑,启用的主题为generatepress


1、进入你的宝塔面板首页

点击文件选项:

给你的wordpress添加文章内图片鼠标点击放大浏览的功能吧~

2、分别找到以下几个文件进行修改

2.1、header.php

<!-- 图片放大 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" />

2.2、footer.php

<!-- 图片放大 -->
<script src="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js"></script>

2.3、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"$6>$7</a>');
    $content = preg_replace($pattern, $replacement, $content);
    return $content;
}

保存退出之后再次点击查看你的文章会出现如下效果:

给你的wordpress添加文章内图片鼠标点击放大浏览的功能吧~

- THE END -

靠谱杨

10月07日16:05

最后修改:2022年10月7日
0

非特殊说明,本博所有文章均为博主原创。

共有 0 条评论