这里分享恢复WordPress图片附件的默认链接形式的方法,适用于文章图片默认不自带自身链接的主题,在主题function.php中添加如下代码:
//图片默认连接到媒体文件(原始链接) update_option('image_default_link_type', 'file');
或者访问 https://yoursite.com/wp-admin/options.php 这个地址,找到 image_default_link_type 填上file即可。
还有另外一种方法,是在主题的header.php文件中添加如下js代码:
<script type="text/javascript"> $(function() { $('.entry img').each(function(i){ if (! this.parentNode.href) { $(this).wrap("<a href='"+this.src+"' class='highslide-image' onclick='return hs.expand(this);'></a>"); } }); }); </script>
需要注意的是,方法二需要你的主题已经加载jq库,如果没有,你可以这样引用:
<script type="text/javascript" src="https://www.rengang.com.cn/wp-content/themes/RG/js/jquery-1.8.0.min.js"></script>" />