0

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?
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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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