WordPress Mixed Content issues and How to fix them

Fix Mixed content issues in WordPress

We have many customers, wondering while they are browsing their website’s pages, sometimes they see an unsecure badge on the top left of their browser. If you do not see the secure lock in your browser address bar then you have a Mixed Content

As you might know Google has announced that going HTTPS will give you a minor ranking boost. Lots of folks rushed into buying SSL-certificates and switching to HTTPS. But after enabling SSL on your webserver remember to test your pages for “absolute” URLs that point to unsecure content – images and scripts.

How to test my website for Mixed Content?

This is very easy. One way (and if you are patient) you can do that by inspecting on Chrome –>

WordPress Mixed Content Issues and SSL

According to Google a mixed Content issue occurs when initial HTML is loaded over a secure HTTPS connection, but other resources (such as images, videos, stylesheets, scripts) are loaded over an insecure HTTP connection.

The mixed content issues, in general are a bit tricky, and hard to find. That’s why on our WordPress Management Services we are using server command tools, to identify the mixed content issues and solve them accordingly. However this action isn’t permanent, so in case someone use again an unsecured HTTP link, for an example in a new post, we need to search into and remove it again.
This is because some plugins and themes hard rewriting the code in a way that some plugins that fixing the mixed content issue (example HTTPS rewrite or SSL Mixed Content Fix plugin) can’t identify and solve the issue because is hard-written into the code, and that’s why we need to do some times manually using the command line and server tools.

Solve the Mixed Content issue in WordPress

There are multiple ways to solve the Mixed Content Issue in WordPress, but the safest and the one we are using is the one that the WP-CLI provide us. WP-CLI is the official command line tool for interacting with and managing WordPress sites and we are happy that we are using it every day!

Fixing the mixed content issues with WP-CLI. To fix the mixed content issues with the wp-cli, you will first need to have SSH access to your website and server, and then you need to install the tool in your server. If you are our Customer you are already have the WP-CLI installed in your server and all you need to do is starting to play with that!

WP-CLI provides a command-line interface for many actions you might perform in the WordPress admin. For instance, wp plugin install --activate (doc) lets you install and activate a WordPress plugin! Fantastic, isn’t it?

$ wp plugin install user-switching –activate

The command will install the plugin User Switching and at the same time with the argument –activate will activate it.

WP-CLI also includes commands for many things you can’t do in the WordPress admin. For example, wp transient delete --all (doc) lets you delete one or all transients. Enough with what WP-CLi can do, you can always search into the DOCS and do amazing things, but let’s get pass to the solution.

Install WP-CLI -> The recommended way to install WP-CLI is by downloading the Phar build (archives similar to Java JAR files, see this article for more detail), marking it executable, and placing it on your PATH.

First, download wp-cli.phar using wget or curl. For example:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Then, check if it works:

php wp-cli.phar --info

To be able to type just wp, instead of php wp-cli.phar, you need to make the file executable and move it to somewhere in your PATH. For example:

chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Now try running wp --info. If WP-CLI is installed successfully, you’ll see output like this:

OS:  Linux 4.10.0-42-generic #46~16.04.1-Ubuntu SMP Mon Dec 4 15:57:59 UTC 2017 x86_64
Shell:   /usr/bin/zsh
PHP binary:    /usr/bin/php
PHP version:     7.3.0-1+ubuntu16.04.1+deb.sury.org+1
php.ini used:   /etc/php/7.3/cli/php.ini
WP-CLI root dir:        /home/wp-cli/.wp-cli
WP-CLI packages dir:    /home/wp-cli/.wp-cli/packages/
WP-CLI global config:   /home/wp-cli/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.3.0

That’s! You’re now an official WP-CLI user!

Fix the mixed Content issues with wp-cli command.

Before continuing you will need to take a full backup of your Database and files. Run into your Hosting’s Dashboard, create a full working backup and you are good to go. Get back in the command line, in your website’s root folder ./myuserverpath/mysitename/public_html and run the following command:

wp search-replace 'http://yourwebsite.com' 'https://yourwebsite.com'  --all-tables --skip-columns=guid --dry-run

With –dry-run the command will not execute, but you will take an output really useful that will tell you what and where will get changed.

Then if you are satisfied by the result , run the command. That’s it! You should be good to go! In case that you have any issues with WP-CLI or any command, let us know in the comments and we will help you!

Another method to fix some of the Mixed Content Issue on WordPress

If you are lucky one and there isn’t anything hard-written in your Database, CSS, js in any other of your files, then the plugin SSL Insecure Content Fixer will do the trick very easy, we have already installed this plugin in hundreds of WordPress installations. Install the plugin, Go in settings and follow the recommended for your website set up:

In any case, and if you have any problems, write in the comments, or send us an email at support [at wordpress-managment.com and we will help you ASAP!

5/5 (2 Reviews)