Dafiul Haq
Dafiul Haq

Reputation: 87

change thumbnail attribute in wordpress?

Is it possible to change the value of the src attribute to another value, and insert the original src value attribute into the new data-src attribute with the_post_thumbnail() function ?

Understood? I want to change this

<img src="img url">

to

<img src="another image" data-src="img url">

Thank you

Upvotes: 0

Views: 254

Answers (1)

Su Yatanar
Su Yatanar

Reputation: 181

For the attribute

Read carefully wordpress documentation.

https://developer.wordpress.org/reference/functions/the_post_thumbnail

the_post_thumbnail( string|array $size = 'post-thumbnail', string|array $attr = '' )

the_post_thumbnail( $size, $attr );

You can change the image url with jquery.

$(document).ready(function(){

      $("#dummyimage").attr("src","http://via.placeholder.com/350x150");


  });
<script
  src="https://code.jquery.com/jquery-1.12.4.js"
  integrity="sha256-Qw82+bXyGq6MydymqBxNPYTaUXXq7c8v3CwiYwLLNXU="
  crossorigin="anonymous"></script>
<img id="dummyimage" src="http://via.placeholder.com/550x350" data-src="img url" />

Upvotes: 1

Related Questions