How can I make uploaded images in the editor load with HTTPS?

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?

Related posts

Leave a Reply

2 comments

  1. This should do it:

    add_action('admin_notices', 'https_the_content');
    function https_the_content() {
    
        global $post;
    
        if(!$post->post_content)
            return;
    
        //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;
    
    }