HiBlog Domains and SSL

How to Fix the Mixed Content Error in WordPress After Enabling HTTPS

  • A. MounesiAuthor
  • Release Date
  • 5 minutesReading time
  • 4Views
  • A. Mounesi
  • Published:
  • 5 min read
  • 4 views
How to Fix the Mixed Content Error in WordPress After Enabling HTTPS

You’ve installed an SSL certificate and the site opens over https, but next to the address you see “Not secure” or a warning instead of the padlock; or some images, fonts and part of the page layout don’t load at all. The culprit is usually one thing: a Mixed Content error, which means the page came over HTTPS but still asks for some of its files from old http addresses.

In this guide you’ll fix the Mixed Content error in WordPress step by step: you find the exact addresses of the http files in the browser, see where on the site they come from and fix them in the WordPress settings, with a search and replace in the database or in the theme and plugins.

Short answer: in Chrome, press F12 and read the Mixed Content messages in the Console tab to see the addresses of the http files. Then, under Settings → General, write both addresses with https and turn the old addresses in the database into https with WP-CLI or the Better Search Replace plugin. Fix any addresses left in the theme, CSS or plugin settings right where they are.

What does Mixed Content mean?

When a page opens over HTTPS, all the files inside it, from images and fonts to scripts and CSS, must come over HTTPS too. If even one of them is requested over http, you have mixed content. The browser upgrades some of these requests to HTTPS by itself and blocks others, especially scripts, completely; the result is a broken page or a security warning.

This error usually appears after you turn on SSL for a site that ran on http for years, because WordPress has stored the full addresses of images and links with http in the database. If the page itself shows a certificate warning before it opens, the problem is something else; see How to Install an SSL Certificate in cPanel first.

The page came over HTTPS, but one of its files is still requested over HTTP

1. Find the http files

Open the problem page in a private window, press F12 and go to the Console tab. Reload the page. Each Mixed Content message has the full address of an http file, for example http://example.com/wp-content/uploads/banner.jpg; note these addresses.

To find out where a request came from, go to the Network tab, tick Disable cache, reload the page and type the file name in the filter box. The Initiator column shows whether the request was sent by the page itself or by a CSS file or script.

Finding the file in the Network tab and reading the Initiator column

2. Switch the site address in WordPress to https

In the dashboard, go to Settings → General and check that “WordPress Address (URL)” and “Site Address (URL)” both start with https. If not, fix them and click Save Changes. Only do this once the site opens over https without a certificate warning and you have a backup of the site.

3. Replace the old addresses in the database

The addresses of images and links inside posts don’t change when you change the settings; they have to be replaced in the database. If you have cPanel’s Terminal or SSH access, do a test run with WP-CLI that changes nothing first, then run it for real:

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

We leave the guid column alone on purpose; it’s the posts’ fixed identifier and must not change. Without a terminal, the Better Search Replace plugin does the same job. Always back up the database before you run it.

4. Check the theme, CSS and plugins

If the Initiator points to a CSS file or script, the http address is probably written in the theme settings, the custom CSS (under Appearance → Customize) or a plugin’s settings; change it to https right there. If the file comes from another service that has no https version, host the file yourself or find another service.

Fixing the address in the same place that produces it

5. Send all visits to https and clear the cache

In cPanel’s Domains section, turn on the domain’s Force HTTPS Redirect switch so anyone who opens an http address goes to https. Then clear your cache plugin’s and CDN’s cache and test the page again in a private window; the padlock should be back next to the address and the Console should have no Mixed Content messages.

FAQ

Isn’t there a plugin that fixes it automatically?

Some plugins turn addresses into https while the page is being shown, but that only covers up the problem and adds extra load to the site every time. The right fix is to replace the addresses once, in the database and the settings.

After the replace, one page still shows a warning. Why?

Probably an old copy of that page is still in the cache, or an http address remains somewhere outside the database, such as the theme’s CSS file or code written straight into the files. Read that page’s Console again.

Free SSL on HiData hosting

On HiData’s professional cPanel hosting, a free SSL certificate is available in your own cPanel, and if a certificate can’t be issued from inside cPanel, you have the free Certify certificate. If you get stuck anywhere after turning on HTTPS, our 24/7 ticket support has your back, and the host’s daily backups make every change reversible!

Share Post

hidata.org/en/blog/fix-mixed-content-https/
In Social Media

Add Comment

Related Articles