wordpress 添加一个灯箱 (文章内所有图片自动灯箱)

加哪都可以,比如footer.php。我是加到single.php(最下面),因为只想对文章生效

<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<link href="https://cdn.bootcss.com/fancybox/3.5.7/jquery.fancybox.css" rel=”stylesheet”>
<script src="https://cdn.bootcss.com/fancybox/3.5.7/jquery.fancybox.js"></script>
<script>
var siteTitle = $("title").html();//获取标题
$(".entry-content img").each(function () {//选取正文的图片
var alt = this.alt;
var src = this.src;
if (!alt) {
$(this).attr("alt", siteTitle);
}
//结构重写
$(this).wrap("<a href='" + src + "' class='fancybox-buttons' data-fancybox-group='button' title='" + alt + "'></a>");
});
//fancybox开始 参数参考 http://fancyapps.com/fancybox/3/
$('.fancybox-buttons').fancybox();
</script>

 

给TA充电
共{{data.count}}人
人已充电
wordpress

【Wordpress】翻译按钮 切换翻译模式

2021-8-29 11:20:25

wordpress

【投稿小技巧】如何插入文章缩略图

2021-9-7 15:23:58

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
今日签到
搜索