I have the admin section of my site using HTTPS. This works pretty well except that the images inside the TinyMCE editor (the post and page rich text editor) load with http instead of https and so I get an "insecure content" warning.

I don't want to change the actual url of the image for front-end users; that is to say when someone visits the blog post normally I want the image to load with plain HTTP. But when I'm editing it should be loaded with HTTPS. How can I do that?

2 Answers 2


This should do it:

add_action('admin_notices', 'https_the_content');
function https_the_content() {

    global $post;


    //change src to use the current url scheme
    $post->post_content = str_replace(array("src=\"http://", "src='http://"), array("src=\"//", "src='//"), $post->post_content);   

    return $post->post_content;

  • I don't think the edit page uses the the_content hook, so we'll need to figure out what the real hook is to use, but yeah otherwise it should work. oh and also we probably need to put in a conditional that if the non-admin page is being served with https then change the protocol to https. oh, and aso maybe put the site url in there after http:// so that it won't changes external images that can't be loaded with/without https (for a third party host)
    – cwd
    Commented Oct 8, 2011 at 19:39
  • edited original with working fix.
    – Ijaas
    Commented Oct 9, 2011 at 16:27

Another way this can work if the images are hosted from your own site is to specify the location using only the path part of the url (i.e. /images/stuff.jpg vs. http://mywordpresssite.com/images/stuff.jpg). This way they'll serve correctly whether you're on https or http.

  • +1 and thanks. This sounds like the best way to do it. I can do this manually but it would be great if the editor used relative paths instead of absolute. Commented Nov 13, 2015 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.