Search code examples
jquerywordpressblogsmedia-library

Update the img src in wordpress media library


I wanted to update the img src rendered in wordpress media library

<a href="https://sample/group/wp-admin/post.php?post=159&amp;action=edit" title="Edit &#8220;NTPIII_Banner_41620134.jpg&#8221;">

<img src="http://sample/group/files/2014/01/NTPIII_Banner_41620134.jpg" class="attachment-80x60" alt="NTPIII_Banner_41620134.jpg" />                </a>

I wanted to replace HTTP to HTTPS as image is not showing when the src is HTTP


Solution

  • Try this:

    $('img').each(function(){
        var newSrc = $(this).attr('src').replace('http', 'https');
        $(this).attr('src',newSrc);
    });
    

    Fiddle:

    http://jsfiddle.net/TWQ3m/