Today’s topic is how to fix mixed content errors on your site. Mixed content is an HTTPS error that occurs when an HTTPS page attempts to serve an HTTP resource, such as an image, video, stylesheet, iframe, or script.
I have marked my favorite tools with a . Earlier this week, I posted Part 1: How to Find Mixed Content.
How to Fix Mixed Content Errors
Mixed content is fixed by replacing the HTTP asset with an HTTPS asset. Where you make the replacement depends on where asset is called from. To make matters more confusing, you can be calling 100% HTTPS assets, but one of those may call a HTTP asset.
Where could an HTTP asset be hiding? It might be in post content, page content, javascript, custom fields, post meta data, theme settings, widgets, themes templates, theme stylesheets, plugins, plugin stylesheets, or plugin templates. Tired yet?
[thrive_2step id=’2681′] [/thrive_2step]
Search and Replace Tools
The easiest mixed content errors to fix are those found in post and page content, such as YouTube videos, or media library embeds. These can be fixed one at a time in the WordPress editor, or en mass with a search-and-replace tools. Always make a backup of your WordPress database before using any kind of search-and-replace tools.
1) Sometimes I use a plugin such as Better Search & Replace, or (my favorite) Better Search & Replace Pro. I prefer the Pro version because it allows me to see the replacements before they are committed to the database.
2) phpMyAdmin is a MySQL tool that is probably included in your hosting package, but is not for the faint of heart.
3) WP-CLI is the WordPress command line. If it’s not installed on your server, ask your host. It is another one of my favorite search and replace tools. Here is the command to search and replace all “http://www.youtube.com” URLs with “https://www.youtube.com” in post and page content.
Want to see WP-CLI in action? Watch me demonstrate how to use the WordPress command line to fix mixed content errors.
[thrive_2step id=’2681′] [/thrive_2step]
Okay, this is a bit off-topic, but here’s another WP-CLI command that will replace all HTTP versions of your URL with the HTTPS version, a very important step in a HTTP to HTTPS conversions. Let’s start with two warnings:
a) Don’t do this replace in serialized data. You’ll break everything! You must use a tool that is serialized-data aware! This means do not use phpMyAdmin (nor a slew of search/replace plugins) to do this replace.
b) Never replace the URL in the GUID column of the wp-posts table.
However, you can (and should) use WP-CLI to perform the search/replace because it is serialized-data aware, and allows you to exclude the GUID. Here’s the command that will replace your HTTP URL in all WordPress tables (if you have extra tables in your database, you might need to specifically include them):
4) If the mixed content is found in a file such as stylesheet or PHP file, you will need a text editor to fix it. My favorite HTML editor is UltraEdit, but I’ve heard rave reviews about PhpStorm. TIP: Do not modify third-party themes, create a child theme instead.
I hope you found this helpful. Below is a bonus video demonstrating how I use the WordPress command line WP-CLI to fix mixed content.
[thrive_2step id=’2681′] [/thrive_2step]
Mixed-content errors are fixed by replacing errant HTTP assets w/ #HTTPS assets. Here's how. #WordPressClick To Tweet