Force WordPress Media button to insert https:// links

I’d previously written a post about forcing the WordPress Media button to insert protocol relative links when running a website as HTTPS-everywhere. Upon further research it turns out that doing so is no longer considered best practice. Paul Irish points out that for security reasons, if an asset is available over https:// then it should be served that way.

Okay, so let’s revise that code a bit to force the WordPress media button to insert https:// instead. Put the following code in either functions.php or you own custom functions plugin:


  • HI,

    This didn’t work for me. After moving to SSL the add media button on post.php page shows blank thumbnails (no preview image) and will insert img src links into the editor with http protocol. Struggling to find a way for the media management tool on post.php to show and handle images properly.

    The odd thing is that upload.php works fine and shows all thumbnail images.

    I’ve tried all the default troubleshooting steps (plugins off, wordpress reinstall, cache off).

    Any idea what could be going on? This issue has plagued me for over a year since I went to ssl and has persisted through the versions of wordpress.


    When I originally moved over to https I added the following to config.php

    `define(‘WP_SITEURL’, ‘’);`

    I removed this and in settings > general and the value for my site address changed back to

    I changed this to https, saved the changes and hey presto, the add media button is up an running – all media thumbnails are showing and when I add media to the posts and it is adding the correct protocol for my site.


      Glad you got this figured out Oliver. Since writing this post, WordPress now uses srcset rather than img for the final output. I haven’t tested the differences from the admin side though.


    Leave a Reply

    Your email address will not be published. Required fields are marked *

    See if Cinch is right for you.

    Ask us anything. Seriously. Like, what is the air speed velocity of an unladen swallow?

    Start a chat right now

    Or go ahead and Sign up now