Fix WordPress Mixed Content Warnings and Force HTTPS

by Fahim Mahmud Chisti

Your SSL certificate is installed and the site loads on https://, but the browser still shows “Not Secure” or a broken padlock. That is WordPress mixed content: the page itself loads over HTTPS, while some images, scripts, stylesheets or fonts still load over plain HTTP. This guide shows how to find those URLs, replace them safely in the database and theme, and force every visit onto HTTPS.

Quick answer: Find the http:// URLs in the browser console, replace them in the database with WP-CLI, fix any hardcoded theme links, then redirect all HTTP traffic to HTTPS.

  1. Open DevTools > Console and note every “Mixed Content” warning.
  2. Set both URLs in Settings > General to https://.
  3. Run wp search-replace 'http://example.com' 'https://example.com' with a dry run first.
  4. Search the theme for hardcoded http:// links and fix them.
  5. Add a 301 redirect to HTTPS in .htaccess or Nginx, then test with curl -IL.
In this guide
  1. Before You Start
  2. Step 1: Find the Insecure Files in Browser DevTools
  3. Step 2: Set the WordPress Address and Site Address to HTTPS
  4. Step 3: Replace HTTP URLs in the Database with WP-CLI
  5. Step 4: Fix Hardcoded Links in Your Theme and Plugins
  6. Step 5: Redirect All HTTP Traffic to HTTPS
  7. Step 6: Add Upgrade-Insecure-Requests as a Safety Net
  8. Step 7: Test the Redirect with curl
  9. If the Padlock Is Still Missing
  10. Frequently Asked Questions
  11. Next Steps
Fix WordPress Mixed Content Warnings and Force HTTPS

Before You Start

  • A working certificate: https://yourdomain.com must already load without a certificate error. This guide fixes the content, not the certificate.
  • Access: WordPress admin, SSH with WP-CLI for the database step, and file access to wp-config.php, .htaccess or your Nginx config.
  • Backup: export the database before the search-replace (Step 3 includes the command). A wrong replace affects every page.
  • Time: 20–40 minutes for most sites.

Step 1: Find the Insecure Files in Browser DevTools

Before you change anything, see exactly what is breaking the padlock. Open your site in Chrome or Firefox, press F12 (or Cmd+Option+I on a Mac, Ctrl+Shift+I on Windows and Linux), and switch to the Console tab.

Each insecure resource shows up as a yellow or red warning like this:

Mixed Content: The page at 'https://example.com/' was loaded over HTTPS,
but requested an insecure element 'http://example.com/wp-content/uploads/2024/05/hero-banner.jpg'.
This request was automatically upgraded to HTTPS.

If a script or API call is blocked, the console says Blocked loading mixed active content. As the MDN mixed content guide explains, browsers block active content (scripts, iframes) outright because unencrypted JavaScript can be changed in transit. For passive content such as images, browsers try HTTPS instead and drop the padlock if that fails.

Note where the flagged URLs come from. It is usually one of these:

  • Old uploads in /wp-content/uploads/, linked with http:// in post content.
  • Hardcoded CSS or JavaScript links in your theme or child theme.
  • External fonts or CDN scripts loaded from http:// addresses.
  • Plugins with hardcoded http:// paths.

Step 2: Set the WordPress Address and Site Address to HTTPS

If WordPress still thinks its address is http://, it keeps generating HTTP links. Go to Settings > General and check that both WordPress Address (URL) and Site Address (URL) start with https://, then save.

If the fields are greyed out, the addresses are set in wp-config.php; edit the existing WP_HOME and WP_SITEURL lines there. If they are not defined and you want to fix them in place, add these lines just above /* That's all, stop editing! Happy publishing. */:

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

These constants override the values stored in the wp_options table. If your site sits behind Cloudflare, a reverse proxy or a load balancer that handles HTTPS for you, WordPress may not know the visitor used HTTPS, which causes a redirect loop. Add this block to wp-config.php, just above the URL lines, so WordPress reads the proxy’s header:

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

Reload the site. If you still get “too many redirects”, see how to fix ERR_TOO_MANY_REDIRECTS on Nginx behind a CDN.

Step 3: Replace HTTP URLs in the Database with WP-CLI

Changing the site address does not touch existing content. Posts, featured images, theme options and page-builder layouts still contain strings like http://example.com/wp-content/uploads/....

Do not run a raw SQL query like UPDATE wp_posts SET post_content = REPLACE(...). WordPress stores widgets, theme settings and page-builder data as serialized PHP strings, which record each string’s length (like s:19:"http://example.com"). Adding one character with a raw replace breaks that count and wipes those settings.

WP-CLI’s search-replace fixes the lengths for you. Connect over SSH, go to your WordPress root, and run a dry run first. It shows how many replacements each table would get and changes nothing:

wp search-replace 'http://example.com' 'https://example.com' --skip-columns=guid --precise --recurse-objects --all-tables --dry-run

If the counts look sensible, export a backup to your home directory and run the real replacement:

wp db export ~/before-https-replace.sql
wp search-replace 'http://example.com' 'https://example.com' --skip-columns=guid --precise --recurse-objects --all-tables

The export ends with a Success: line naming the file, and the replacement ends with a summary of how many changes it made. Here is what the flags do:

  • --skip-columns=guid: leaves post GUIDs (permanent post IDs) alone, as the WordPress documentation recommends, so feed readers do not treat old posts as new.
  • --precise: uses the slower PHP-based replacement on every column instead of the SQL shortcut WP-CLI uses for columns without serialized data.
  • --recurse-objects: also replaces inside serialized objects (this is the default behavior).
  • --all-tables: covers every table, including plugin tables (WooCommerce, form plugins, page builders) that are not registered with WordPress core.

When it finishes, flush the object cache:

wp cache flush

For more search-replace options and how to undo a bad run, see the guide to safely updating URLs with WP-CLI search-replace.

If DevTools still shows warnings after the database replace, the URLs are probably hardcoded in template files (like header.php or footer.php) or enqueued in functions.php.

Look for script or stylesheet registrations with an http:// address:

// INCORRECT: Hardcoded HTTP external font
wp_enqueue_style('custom-google-fonts', 'http://fonts.googleapis.com/css?family=Inter:400,700');
// CORRECT: Protocol-relative or explicit HTTPS URL
wp_enqueue_style('custom-google-fonts', 'https://fonts.googleapis.com/css?family=Inter:400,700');

For files inside your own theme, never hardcode the domain. Use WordPress helper functions, which build the URL with the site’s current protocol:

// Standard dynamic script enqueueing
wp_enqueue_script(
    'custom-script',
    get_stylesheet_directory_uri() . '/js/app.js',
    array( 'jquery' ),
    '1.0.0',
    true
);

To find every hardcoded HTTP link in the theme, run grep over SSH from the WordPress root:

grep -rn "http://" wp-content/themes/your-active-theme/

Each match prints the file name, line number and the line itself. No output means the theme has no hardcoded HTTP links. Change the matches to HTTPS or to WordPress helper functions. To test theme edits without risking the live site, create a WordPress staging site in Hostinger hPanel first.

Step 5: Redirect All HTTP Traffic to HTTPS

Fixing the content handles the page’s files, but visitors who type your domain without https://, or follow old links, can still land on plain HTTP. A server-level 301 (permanent) redirect sends them to HTTPS before WordPress even loads.

On Apache or LiteSpeed (.htaccess)

Open .htaccess in your WordPress root and paste this block at the very top, above # BEGIN WordPress:

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

If your server sits behind a proxy or load balancer that handles HTTPS, use this version, which also checks the forwarded protocol header:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

On Nginx (Server Block)

On Nginx, give HTTP (port 80) its own server block that only redirects. Open your site’s configuration (usually /etc/nginx/sites-available/example.com) and set it up like this:

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

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com www.example.com;

    ssl_certificate /etc/ssl/certs/example.com.crt;
    ssl_certificate_key /etc/ssl/private/example.com.key;

    root /var/www/html;
    index index.php index.html;

    # ... remainder of your WordPress location blocks
}

If you are installing the certificate files by hand, see how to install a Namecheap SSL certificate on Nginx.

Check the syntax and reload Nginx:

sudo nginx -t && sudo systemctl reload nginx

You should see syntax is ok and test is successful; if not, the reload does not run and the old config stays active.

Step 6: Add Upgrade-Insecure-Requests as a Safety Net

On a large site with thousands of old posts or user embeds, some stray http:// links may survive. A Content Security Policy (CSP) header can tell browsers to fetch them over HTTPS automatically. According to the MDN Upgrade-Insecure-Requests documentation, browsers then rewrite http:// resource URLs to https:// before sending the request.

Use one of these three options, not all of them.

Option A: Nginx

In your port 443 server block, add:

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

Option B: Apache or LiteSpeed (.htaccess)

Add this to your .htaccess file:

<IfModule mod_headers.c>
    Header always set Content-Security-Policy "upgrade-insecure-requests;"
</IfModule>

Option C: PHP in functions.php

If you cannot edit server files, send the header from your active theme’s (or child theme’s) functions.php:

function isitdev_force_ssl_header() {
    header( 'Content-Security-Policy: upgrade-insecure-requests;' );
}
add_action( 'send_headers', 'isitdev_force_ssl_header' );

To check the header is sent, run curl -I https://example.com and look for a content-security-policy line. This header cannot help with files on external servers that do not support HTTPS at all; those still need replacing or hosting locally.

Step 7: Test the Redirect with curl

Finally, check that HTTP redirects cleanly to HTTPS without a loop. Run this in your local terminal:

curl -IL http://example.com

You should see a single 301 Moved Permanently followed by a 200 from the HTTPS address, similar to this:

HTTP/1.1 301 Moved Permanently
Server: nginx
Location: https://example.com/

HTTP/2 200
server: nginx
content-type: text/html; charset=UTF-8

Then reload your site with DevTools open. The console should show no Mixed Content warnings, and the padlock should be back. For WordPress’s own guidance, see the WordPress HTTPS documentation.

If the Padlock Is Still Missing

  • Warnings persist after the database replace. A page cache, object cache (Redis, Memcached), Varnish or CDN is still serving old HTML. Purge your cache plugin and CDN, then test in a private window.
  • Page-builder pages still load HTTP files. Some builders save generated CSS files with full URLs. Regenerate the CSS from the builder’s tools screen after the search-replace.
  • The curl test shows a chain of 301s back to the same URL. Your proxy or CDN and the server disagree about HTTPS. Add the X-Forwarded-Proto block from Step 2, or use the proxy version of the .htaccess rule.
  • One external file stays blocked. Its server has no working HTTPS. Download it and host it yourself, or remove it.

Frequently Asked Questions

What is the difference between active and passive mixed content?

Active content can change the page; passive content cannot. Scripts, iframes and stylesheets are active, so browsers block them when they load over HTTP. Images, audio and video are passive, so browsers usually try HTTPS first and remove the padlock or block the file if that fails.

Can I just use the Really Simple SSL plugin instead?

You can, but it treats the symptom. Plugins like Really Simple SSL rewrite http:// to https:// in the page output on every request, which adds a little PHP work to each page. Replacing the URLs once in the database and redirecting at the server level is a permanent fix with no ongoing cost.

What happens if an external image source does not support HTTPS?

The browser blocks it or drops your padlock, whatever your own settings say. Download the image, upload it to your Media Library, and update the link so it points to your own HTTPS domain.

Does forcing HTTPS hurt my SEO rankings?

No. Google uses HTTPS as a ranking signal, and with 301 redirects in place, search engines move your pages’ ranking signals to the HTTPS URLs. Make sure the https:// version of your site is added and verified in Google Search Console.

Next Steps

  1. Browse a few old posts and your shop or contact pages with DevTools open to catch any remaining warnings.
  2. Check that https:// is the property you monitor in Google Search Console.
  3. Keep the database export from Step 3 until you are sure everything works, then delete it from the server.
all_in_one_marketing_tool