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 recently converted my WordPress installation to use SSL on all pages, and now I'm getting mixed content warnings. I've cleaned up everything in my themes and admin pages, but I'm still having trouble with embedded/attached content.

Most posts include uploaded images, and in the post_content those images are still referred to using an http:// URL. How can I permanently fix this and stop the mixed content warnings?

  • Should I try to fix all of the posts in the database so that they have correct https URLS?
  • Is there a way to dynamically rewrite posts as they are shown to use https URLS?
share|improve this question
    
This forum thread discusses why absolute links are used: wordpress.org/support/topic/… –  Nic Nov 5 '11 at 20:09

1 Answer 1

Figured it out! The function I needed to hook is called "the_content", because that's the post content that is pulled directly from the database.

I added this code into the functions.php file for my theme.

function force_https_the_content($content) {
  if ( is_ssl() )
  {
    $content = str_replace( 'src="http://', 'src="https://', $content );
  }
  return $content;
}
add_filter('the_content', 'force_https_the_content');
share|improve this answer

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.