Skip to content

How to Fix Mixed Content Errors in WordPress, Step by Step

Fix mixed content in WordPress step by step: find insecure HTTP files with DevTools, update site URLs, run a safe search-replace and enforce HTTPS redirects.

By Devma Hosting Team · · 11 min read

A brass padlock on a wooden desk next to an out-of-focus laptop, coffee mug and notebook in warm morning light.

To fix mixed content in WordPress, find every file that still loads over http://, then correct it at the source: switch your site URLs to HTTPS, run a safe database search-replace, and edit any hardcoded links in your theme, plugins or widgets. Then force HTTPS with a 301 redirect and, if you like, add an upgrade-insecure-requests header as a safety net.

The steps below work whether you have shell access or only the WordPress dashboard.

Key takeaways

  • Mixed content happens when an HTTPS page loads images, scripts, stylesheets, fonts or iframes over plain HTTP. Browsers block scripts, stylesheets and iframes outright and try to auto-upgrade plain images, audio and video.
  • Images in srcset and CSS url() values can still be blocked, so "the images show up" does not mean the problem is fixed.
  • The reliable fix is a database search-replace with a serialization-aware tool (WP-CLI or Better Search Replace), run after a backup and a dry run, skipping the guid column.
  • WordPress Site Health can report your site as secure while the database still contains HTTP links.
  • Add a sitewide 301 redirect to HTTPS, clear every cache, and treat upgrade-insecure-requests as a backup, not the fix.

What is a mixed content error in WordPress?

A mixed content error appears when a page delivered over HTTPS pulls in resources over HTTP. The page itself is encrypted, but those extra requests are not, so the browser removes the padlock, shows a warning, or refuses to load the files.

The terminology has changed, which is why older tutorials can be confusing. The W3C Mixed Content specification now splits mixed content into upgradeable and blockable. What used to be called "optionally-blockable" (or "passive") is now upgradeable, and everything else is blockable. According to MDN, browsers should automatically upgrade upgradeable requests from HTTP to HTTPS and block the rest.

In practice, only img, audio and video elements are treated as upgradeable, as noted in this MDN content discussion. That matters a lot for WordPress:

Resource in your page What modern browsers do What you should do
<img src="http://..."> Rewrites the request to https:// (no fallback if that fails) Fix the URL anyway
Image URLs inside srcset or <picture> Blocked Fix the URL
<script src="http://..."> Blocked Fix the URL
<link rel="stylesheet" href="http://..."> Blocked Fix the URL
Iframes and embeds over HTTP Blocked Fix or replace the embed
CSS url() for fonts and backgrounds Treat as blocked Fix the URL

Two details catch people out. First, WordPress core outputs responsive images with srcset, and a practitioner test in recent Chromium found that images set through src were upgraded while those set through srcset were blocked. Second, auto-upgrading has no fallback: if the image host does not answer on HTTPS, the image simply fails. MDN also warns that some upgradeable content may become blockable in the future, so think of auto-upgrade as a safety net, not a solution.

Sources are inconsistent about CSS background images (MDN has listed them in both categories), so the safe approach is to fix every CSS url() value too. Exact behavior can also vary between browsers, so test in more than one.

Step 1: Confirm your SSL certificate is valid

Mixed content fixes are pointless if the certificate itself is broken. Before touching WordPress, confirm that the certificate covers your exact hostnames (both example.com and www.example.com if you use both), has not expired, and serves the full certificate chain.

Run your domain through our free SSL Checker, or an external tester such as SSL Labs. If you see chain errors or a hostname mismatch, fix those with your host first. A broken certificate produces its own browser warning that no amount of URL editing will remove.

Step 2: Find the mixed content with browser DevTools

The browser will tell you exactly which files are the problem.

  1. Open an affected page in Chrome, Edge or Firefox.
  2. Press F12 (or right-click and choose Inspect) and open the Console tab.
  3. Reload the page with the console open.
  4. Read the messages. A yellow warning ending in "This request was automatically upgraded to HTTPS" means an image was upgraded. A red error ending in "This request has been blocked; the content must be served over HTTPS" means a file was blocked.
  5. Switch to the Network tab, reload, and type http:// into the filter box to list every insecure request.

Note the domain on each URL. Requests to your own domain are fixed in the database or theme. Requests to third-party domains need a different approach (covered in Step 6).

Check several page types, not just the home page: a blog post, a page built with your page builder, a product page if you run a store, and an archive page. Mixed content often lives in one template or one old post.

Don't rely on Site Health alone

Tools > Site Health in WordPress checks whether your site uses HTTPS, but it only looks at how the site is served. As WP Tavern explains, Site Health considers the site secure as long as it is served over HTTPS, even if your content still contains HTTP links. A green result there does not mean you are done.

Step 3: Back up your site before you change anything

The next steps edit your database. Take a full backup of files and database, and make sure you know how to restore it. Our guide on how to back up a WordPress site and actually restore it walks through this.

WP Engine's search-replace documentation puts it plainly: run every command with --dry-run first and make a new restore point before executing. If you have WP-CLI, a quick database export takes seconds:

wp db export before-https-fix.sql

Step 4: Update the WordPress site URLs to HTTPS

WordPress stores two key addresses: WordPress Address (URL) and Site Address (URL). The official migration docs describe them as the settings that control where WordPress is located.

You have three ways to change them.

Option A: Settings > General. Change both fields from http:// to https://, save, and log in again when prompted.

Option B: The one-click button. Since WordPress 5.7, if your server already supports HTTPS, Site Health shows a button that switches both URLs at once, as described in the core dev note. Sources disagree about how far this goes. Our reading, which matches WP Tavern, is that it updates the two URL settings and makes WordPress rewrite links to your own domain in content as pages are displayed, without permanently changing what is stored in the database. Either way, a proper search-replace in Step 5 is still the thorough fix.

Option C: wp-config.php. Hardcode the values, which also locks them so they cannot be changed in the dashboard:

define( 'WP_HOME', 'https://example.com' );
define( 'WP_SITEURL', 'https://example.com' );

If you ever used the RELOCATE constant to recover a site, remove it now. The WordPress docs warn that leaving it in wp-config.php is insecure, because in some configurations it lets an attacker change your site URL.

Step 5: Run a safe database search-replace to fix mixed content

This is the core fix. Every post, page, widget and option that contains http://example.com needs to become https://example.com.

Why not just run SQL?

WordPress stores many plugin settings, widget configurations and theme options as PHP serialized strings, which record the length of each value. A raw SQL REPLACE() changes http to https (one character longer) without updating that length, and the data becomes unreadable, as this WP-CLI guide explains. Use a tool that handles serialization.

Also, never touch the guid column. The WordPress docs say to never change its contents under any circumstances. It is an identifier, not a link, and feed readers rely on it.

The WP-CLI search-replace command handles serialized data safely. Start with a dry run:

wp search-replace 'http://example.com' 'https://example.com' \
  --all-tables-with-prefix \
  --skip-columns=guid \
  --precise \
  --report-changed-only \
  --dry-run

Review the table of changes. If the numbers look sensible, run the same command without --dry-run.

What the flags do:

Flag Purpose
--dry-run Shows what would change without saving anything
--all-tables-with-prefix Includes tables created by plugins that use your table prefix
--skip-columns=guid Leaves post GUIDs untouched
--precise Uses PHP instead of SQL, which is more thorough but slower
--report-changed-only Hides tables with zero matches
--export=file.sql Writes the changes to a file instead of the live database

Avoid --regex unless you really need it. The docs note it makes the command roughly 15 to 20 times slower.

Catch the variants a simple search misses

A single search often leaves stragglers. Repeat the dry run, then the real run, for each of these:

# The www version of your domain
wp search-replace 'http://www.example.com' 'https://www.example.com' --all-tables-with-prefix --skip-columns=guid --dry-run

# JSON-escaped URLs (common in page builders and block attributes)
wp search-replace 'http:\/\/example.com' 'https:\/\/example.com' --all-tables-with-prefix --skip-columns=guid --dry-run

# URL-encoded URLs
wp search-replace 'http%3A%2F%2Fexample.com' 'https%3A%2F%2Fexample.com' --all-tables-with-prefix --skip-columns=guid --dry-run

The escaped and encoded patterns follow the approach in this WP-CLI HTTPS guide. Including the domain in each pattern keeps you from accidentally changing links to other sites that may not support HTTPS.

Without shell access

If your host does not offer SSH, install a plugin such as Better Search Replace, then go to Tools > Better Search Replace. Enter the old and new URLs, select all tables, tick the dry run box, and review the report before running it for real. Guides from Hostinger and weDevs show the screens. You can deactivate and delete the plugin afterward.

If the console still shows HTTP requests to your own domain after the search-replace, the URLs are probably written into files rather than the database. Check these places:

  • Theme files such as header.php, footer.php and functions.php, especially wp_enqueue_script() and wp_enqueue_style() calls.
  • Theme CSS files, looking for url(http://...) in fonts and backgrounds.
  • Appearance > Customize > Additional CSS.
  • Custom HTML widgets and header or footer script fields in theme or SEO plugin settings.
  • Page builder templates that store their own CSS files. Some builders have a "regenerate CSS" option to use after URL changes.

In your own code, avoid literal URLs. Use WordPress functions such as home_url(), site_url(), get_template_directory_uri() and get_stylesheet_directory_uri(), which follow your site settings automatically.

If the culprit is a commercial plugin or theme, update it first. If a vendor's code still hardcodes HTTP, report it to them rather than editing their files, since your changes would be overwritten on the next update.

Third-party files that don't support HTTPS

For resources on other domains, first try the same URL with https:// in a new tab. If it loads, update the link. If it does not, nothing on your side can upgrade it, because browsers do not fall back to HTTP. Your choices are to host the file yourself, switch to a provider that supports HTTPS, or remove it.

Step 7: Clear every cache

After the changes, old HTML with HTTP links may still be served from cache. Clear, in this order:

  1. Your caching plugin's page cache.
  2. The object cache (wp cache flush with WP-CLI).
  3. Any server-level cache your host provides.
  4. Your CDN cache.
  5. Your own browser cache, or test in a private window.

Then repeat the DevTools check from Step 2 on the same set of pages.

Step 8: Force HTTPS with a 301 redirect

Now make sure nobody can reach the HTTP version. On Apache, add this to .htaccess above the # BEGIN WordPress block, as the WordPress HTTPS docs advise:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

On Nginx, add a server block for port 80:

server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}

Behind a CDN, proxy or load balancer

If HTTPS ends at a CDN or load balancer, WordPress may think every request is HTTP, which causes redirect loops or HTTP asset URLs. The same WordPress doc shows the fix. Add this to wp-config.php above the line that loads wp-settings.php:

if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && strpos( $_SERVER['HTTP_X_FORWARDED_PROTO'], 'https' ) !== false ) {
    $_SERVER['HTTPS'] = 'on';
}

To enforce HTTPS for logins and the dashboard, also add:

define( 'FORCE_SSL_ADMIN', true );

Should you add the upgrade-insecure-requests header?

The upgrade-insecure-requests Content Security Policy directive tells the browser to upgrade every HTTP request on your pages to HTTPS, including scripts and stylesheets that would otherwise be blocked. MDN's CSP guide explains it exists because rewriting every URL can be very difficult, or effectively impossible for archived content.

It is a useful backstop once you have done the real fix. On Apache:

Header always set Content-Security-Policy "upgrade-insecure-requests"

On Nginx:

add_header Content-Security-Policy "upgrade-insecure-requests" always;

It has the same limitation as browser auto-upgrades: no fallback. Anything hosted on a server without HTTPS still breaks, so test after enabling it. If you already send a CSP header, add the directive to it instead of creating a second header.

Don't use block-all-mixed-content. MDN marks it as obsolete, and upgrade-insecure-requests is evaluated before it anyway.

What about HSTS?

HTTP Strict Transport Security tells browsers to only ever use HTTPS for your domain. Add it only after the site works fully over HTTPS, start with a short max-age, and increase it once you are confident. Submitting your domain to browser preload lists is hard to undo, so treat that as a separate, deliberate decision. For other ways to harden your site, see our WordPress security checklist.

Common mistakes when fixing mixed content

  • Using raw SQL instead of a serialization-aware tool, which corrupts widgets and settings.
  • Changing the guid column.
  • Skipping the backup and dry run.
  • Searching only one URL form and missing www, JSON-escaped, URL-encoded or plugin-table URLs.
  • Stacking several "SSL fixer" plugins that rewrite output. One is the maximum, and ideally you need none once the data is clean.
  • Forgetting caches, then assuming the fix did not work.
  • Not configuring proxy HTTPS detection, leading to redirect loops.

If you are moving hosts at the same time, do the HTTPS switch as part of the migration plan. Our guide to migrating WordPress with zero downtime shows where it fits.

Get HTTPS right from day one with the right hosting

Mixed content problems often come from a site that started on HTTP and switched later. Starting on hosting that issues and renews certificates automatically, and gives you WP-CLI or SSH access and control over redirects, avoids much of this work. Those are good things to check when you compare plans, including Devma Hosting's WordPress Hosting. If you would rather hand off cleanup and ongoing checks, see our Website Maintenance page.

Frequently asked questions

Why does my WordPress site still say "Not secure" after I installed an SSL certificate?

Installing a certificate only makes HTTPS available. If your site URLs are still set to http://, or pages still load scripts, stylesheets or images from http:// addresses, the browser drops or downgrades the padlock. Check the certificate first, then open the browser console to see exactly which files are still insecure.

Do I need a plugin like Really Simple SSL to fix mixed content?

No. Plugins of this kind can help, but many work by rewriting pages as they are served instead of fixing the stored data, so the underlying HTTP links remain. A one-time database search-replace plus an HTTPS redirect is the cleaner fix. If you do use a plugin, run only one, because several output-rewriting plugins together can conflict.

Will a database search-replace break my WordPress site?

It is safe when you use a tool that understands serialized data, such as WP-CLI or Better Search Replace, take a backup first and preview with a dry run. The risky approaches are raw SQL REPLACE() queries, which can corrupt serialized settings, and changing the guid column. Keep a tested backup so you can roll back if anything looks wrong.

What if an external script or image only works over HTTP?

No rewrite or header can fix it, because browsers do not fall back to HTTP after upgrading or blocking a request. Download the file and host it on your own site, switch to a provider that supports HTTPS, or remove the resource. This is also why upgrade-insecure-requests should be tested before you rely on it.

Abstract blue swirling shapes with light reflections

Ready when you are.

Pick a plan and launch today, or tell us what you run and we will size it with you.

Devma Hosting

AI assistant · replies in seconds

Hi there.
How can we help?

Ask about plans, moving your site, email or security. Answers come from our own guides, and a person is one tap away.

  • Message us on WhatsApp