X
X
X
X

Mixed Content Error: How to Fix Not Secure Warnings on an HTTPS Site

HomepageArticlesWeb Security & SSLMixed Content Error: How to Fix Not...

In short: A mixed content error happens when a page loaded over HTTPS still tries to load some of its resources, such as images, scripts, stylesheets or fonts, from an unencrypted http:// address. The browser may then remove the padlock from the address bar, show a "not secure" warning or refuse to load the resource at all, which breaks part of the page. The fix is to find every http:// reference on the page and change it to https://: first spot the failing resources in the browser console, then correct the old addresses in the database and in theme and plugin files.

What is a mixed content error?

"Mixed content" means that secure (HTTPS) and insecure (HTTP) resources appear together on the same page. Even if the page itself is encrypted with an SSL certificate, a single embedded http:// resource lets an attacker read or change that resource on its way to the visitor. That is why browsers take mixed content seriously (MDN: Mixed content).

The error usually appears after a site moves from HTTP to HTTPS. The certificate is installed and the site opens with https://, but old http:// addresses saved over the years in posts, theme settings and plugin options stay where they were. For every step of the move, see our HTTP to HTTPS migration guide; this article focuses on the mixed content that is left over afterwards. If you want a quick summary of what a certificate does, read what is an SSL certificate.

Why does the browser say "not secure"?

Browsers split mixed content into two groups:

  • Upgradable content: Images, audio and video. Current browsers automatically retry these resources over https://. If the resource is not served over HTTPS, it fails to load and you see a broken image on the page.
  • Blockable content: Scripts (JavaScript), stylesheets, iframes, fonts and other requests the page makes. Because these can change the whole page, the browser blocks them when they come from an http:// address.

As a result, a mixed content error can show up with two different symptoms: the padlock in the address bar disappears or turns into a warning, or menus, sliders, forms or the design stop working. In the second case the visitor may never see a security warning, but the site looks broken.

How to find mixed content resources

  1. Open the browser console. On the affected page press F12 and switch to the Console tab. Mixed content warnings start with "Mixed Content" and name the exact http:// address that was loaded or blocked.
  2. Search the page source. Open the page source (Ctrl+U) and search for "http://". Old addresses that start with your own domain usually come from the database; those on other domains usually come from the theme, plugins or embedded code.
  3. Check different page types. Even if the home page is clean, blog posts, product pages, the contact form or archive pages can use different templates. Check at least one page of each template.

Write the addresses you find in a list and group them by source: content in the database, theme files, plugin settings and external resources. Each group is fixed in a different way.

Fixing mixed content: find console warnings, replace http:// with https:// in the database, fix theme links, add CSP, secure padlock

How to fix a mixed content error step by step

  1. Take a backup first. You are about to make bulk changes in the database, so take a fresh backup of your files and database before you start.
  2. Switch the site address to HTTPS. If you use WordPress, make sure the WordPress Address (URL) and Site Address (URL) fields under Settings > General start with https://.
  3. Replace old addresses in the database. Change the http:// addresses stored in post content and settings to https://. If you can use WP-CLI, the search-replace command is built for this and changes WordPress serialized data without breaking it. Run it with --dry-run first to see how many records will change (WP-CLI search-replace):
    wp search-replace 'http://example.com' 'https://example.com' --dry-run
    If the result is what you expect, run the same command without --dry-run. Running a plain text replace query directly in the database is not recommended, because it can break serialized data.
  4. Fix theme and plugin files. Addresses that appear in the console but not in the database are usually hard-coded in theme files, in background-image rules inside CSS or in plugin settings. Change them to https://. A theme update can overwrite your edits, so making them in a child theme is safer.
  5. Review external resources. If a script or image loaded from another site does not support HTTPS, use its HTTPS address, host the file on your own server or remove it from the page.
  6. Add CSP as a safety net. The upgrade-insecure-requests directive of the Content-Security-Policy header tells the browser to make the page's http:// requests over https:// instead. On Apache servers you can add this line to the .htaccess file:
    Header always set Content-Security-Policy "upgrade-insecure-requests"
    The directive catches what is left, but it does not replace the real fix: if the resource is not served over HTTPS the request fails and the browser does not fall back to HTTP (MDN: upgrade-insecure-requests). It does not replace HSTS either; see what is HSTS for the difference.

Clear the cache and check again

If the error still seems to be there after your fixes, the most common reason is caching. If you use a page cache plugin, a CSS and JavaScript optimisation plugin or a CDN, clear their caches, then empty your own browser cache as well. The steps for each browser are in our clear browser cache article. Then open the console again and recheck the same pages: no "Mixed Content" warning should remain and the padlock in the address bar should look normal.

Quick checklist

  • The site address and WordPress address start with https://.
  • http:// addresses in the database were replaced after a backup.
  • No hard-coded http:// links remain in the theme, child theme or plugin settings.
  • External resources without HTTPS support were removed or replaced.
  • Caches were cleared and different page types were checked in the console.

Once the mixed content is fixed, our WordPress security checklist is a good next step for reviewing the overall security of your site.

Frequently Asked Questions

Does a mixed content error mean my SSL certificate is broken?

No. The certificate can be perfectly valid; the problem is that the page still loads some resources from http:// addresses. Replacing the certificate does not fix this error.

Can a plugin fix mixed content completely?

Some plugins rewrite addresses in the page output on the fly, but that is not a permanent fix. Correcting the addresses in the database and theme files is the cleaner solution.

Why do images fail and scripts stop working?

Browsers retry images, audio and video over HTTPS; if the resource is not served over HTTPS it fails to load. Scripts, stylesheets and iframes coming from http:// are blocked outright.

Is adding upgrade-insecure-requests enough?

Not on its own. The directive upgrades the remaining requests to HTTPS, but if a resource is not served over HTTPS the request fails. The real fix is correcting the addresses at their source.


Powered by WISECP
Top