加哪都可以,比如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>