Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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;

}
share|improve this answer
    
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 Oct 8 '11 at 19:39
    
edited original with working fix. –  Ijaas Oct 9 '11 at 16:27
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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