【问题标题】:trying to fix images not appearing on wordpress site试图修复没有出现在 wordpress 网站上的图像
【发布时间】:2018-02-15 17:25:44
【问题描述】:

在一个版本的 chrome 中,当我检查图像时我会得到这个

<img src="http://esg.com/wp-content/uploads/2016/03/ESG-hudsonlg-01-600x548.jpg?x80200" data-lazy-type="image" data-src="http://esg.com/wp-content/uploads/2016/03/ESG-hudsonlg-01-600x548.jpg?x80200" class="lazy-loaded">

在较新的版本中,图像不加载,我得到了这个代码

<img src="" data-lazy-type="image" data-src="http://esg.com/wp-content/uploads/2016/03/ESG-hudsonlg-01-600x548.jpg?x80200" class="lazy-hidden">

解决/纠正丢失的图像链接的任何想法?谢谢!!

【问题讨论】:

标签: jquery html wordpress image


【解决方案1】:

jQuery(document).ready(function($){
    $('.lazy-hidden').each(function(){
      var src = $(this).attr('data-src');
      $(this).attr('src',src);
        
    })
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<img src="" data-lazy-type="image" data-src="http://elizabethstreetgallery.com/wp-content/uploads/2016/03/ESG-hudson-mirrors-sm-lg-01-600x548.jpg?x80200" class="lazy-hidden">
<br />
<img src="" data-lazy-type="image" data-src="http://elizabethstreetgallery.com/wp-content/uploads/2016/03/ESG-hudson-mirrors-sm-lg-01-600x548.jpg?x80200" class="lazy-hidden">


<!-- I had used demo image src as your src is not opening in browser too. -->

如果您发布了代码会更好,但您可以使用此 hack 来实现您的要求。

编辑 让我告诉我我在这里做了什么,我将每个图像的当前data-src 分配给它一个变量,然后将当前图像src 替换为data-src。

谢谢

【讨论】:

  • 嗨 Bilal,非常感谢您的来信。这是确切的代码...工作... elizabethstreetgallery.com/wp-content/uploads/2016/03/…" data-lazy-type="image" data-src="elizabethstreetgallery.com/wp-content/uploads/2016/03/…" class="lazy-loaded"> 不工作。 .. elizabethstreetgallery.com/wp-content/uploads/2016/03/…" class="lazy-hidden">
  • 我使用了两张图片,所以你在动态运行这个js或者多张图片时不会有任何问题。
  • 嗨 bilal,非常感谢您的回答。如果整个站点都发生这种情况,我是否需要对每个实例进行更改,或者上面的代码是否涵盖了全局?
  • 不,您不需要对每个实例进行更改。只需将此 js 粘贴到页脚并确保所有图像都添加了“.lazy-hidden”类。谢谢
猜你喜欢
  • 1970-01-01
  • 2012-12-16
  • 1970-01-01
  • 2013-05-05
  • 2021-12-25
  • 2022-07-21
  • 1970-01-01
  • 1970-01-01
  • 2019-03-15
相关资源
最近更新 更多