To fix the mixed content error WordPress shows after an SSL move, stop guessing and start logging: the browser already knows which asset is still being requested over http://, and a Content-Security-Policy-Report-Only header can write that list to your server log. This guide compares the short-cut fixes you will find in forum threads, explains when each one actually fits, then implements the recommended workflow in full: a serialisation-safe WP-CLI search-replace, a small filter for builder JSON and theme CSS, and the proxy settings that stop is_ssl() returning false long after the certificate is live.
You will need: shell access with WP-CLI 2.x installed on the server, a database backup (or a staging clone you can break), and permission to drop a file into wp-content/mu-plugins/.
From experience · Md. Zubaer Ahammed
WP Tuts Hub itself runs behind Cloudflare and a reverse proxy, so PHP never sees the HTTPS connection directly. The forwarded-protocol check from this guide is in this site's own wp-config.php for exactly that reason.
Why the padlock still breaks when the site URL already says https://
WP_HOME and WP_SITEURL only govern the URLs WordPress generates. Anything typed into post content, pasted into a widget, stored in an options row, baked into a theme stylesheet or serialised inside a page builder's JSON stays exactly as it was written: http:// and all. The browser then refuses to mix an insecure subresource into a secure document.
The severity differs by asset type. Scripts, stylesheets, iframes and XHR calls are blocked outright, so the page loads with broken layout or dead interactivity. Images and media are usually auto-upgraded to https:// first and only blocked if that upgrade fails, which is why a site can look mostly fine while the Console tab is full of red. Before you change a single row, open DevTools, reload the offending page, and read the Console entries: each one names the exact URL the browser refused.
Three routes to a green padlock, and when each one is the right call
Route 1: a search-replace plugin through wp-admin
Tools such as Better Search Replace run inside a browser request and handle serialised data correctly. They are genuinely useful when you have no shell access and the database is small. The limits appear quickly: a large wp_postmeta table times out mid-run, the browser gives you no per-table report, and a half-finished replace leaves you guessing which tables were touched. Good for a 20-page brochure site; poor for anything with a builder installed.
Route 2: a blanket output buffer that rewrites the final HTML
The tempting one-liner is ob_start() plus a str_replace() over the finished page. It hides the symptom and creates new problems: full-page caches store the rewritten HTML while REST responses, feeds and XML sitemaps bypass it; Content-Length and ETag calculations can go stale; and, most damaging, a block editor or builder that posts its rendered markup back to the server will happily save the rewritten version, or fight your buffer on every autosave. Treat this as a debugging experiment, never a fix.
Route 3: log with CSP Report-Only, then replace with WP-CLI
This is the route implemented below. You add a header that reports violations without blocking anything, collect a precise inventory of offending URLs, then repair the database once with a tool that understands serialised arrays. Residual hardcoded strings in theme CSS and builder data get a narrow render-time filter, and proxy setups get an explicit protocol fix. It is more steps, but every step is reversible and observable, which is what you want on a live site.
Step 1: Log every blocked request with a Report-Only policy
A report-only policy sends the browser's violation reports to an endpoint while letting the page load normally. Register a small REST route to receive them and log the blocked URI with the page it appeared on. Drop this in wp-content/mu-plugins/wpth-csp-report.php.
<?php /** * Plugin Name: WPTH Mixed Content Report Logger * Description: Reports http:// subresources without blocking them. */ add_action( 'send_headers', function () { if ( is_admin() || wp_doing_ajax() || wp_doing_cron() ) { return; } $policy = "default-src https: data: blob: 'unsafe-inline' 'unsafe-eval'; " . 'report-uri /wp-json/wpth/v1/csp-report'; header( 'Content-Security-Policy-Report-Only: ' . $policy ); } ); add_action( 'rest_api_init', function () { register_rest_route( 'wpth/v1', '/csp-report', array( 'methods' => 'POST', 'permission_callback' => '__return_true', 'callback' => function ( WP_REST_Request $request ) { // Browsers post reports as application/csp-report, which get_json_params() does not parse. $payload = json_decode( $request->get_body(), true ); $report = isset( $payload['csp-report'] ) ? $payload['csp-report'] : array(); if ( ! empty( $report['blocked-uri'] ) ) { error_log( sprintf( '[wpth-csp] %s on %s', sanitize_text_field( $report['blocked-uri'] ), esc_url_raw( isset( $report['document-uri'] ) ? $report['document-uri'] : '' ) ) ); } return new WP_REST_Response( null, 204 ); }, ) ); } ); The handler reads the raw request body on purpose. Browsers post these reports as application/csp-report, which WordPress does not treat as JSON, so get_json_params() returns null and nothing would ever be logged.
Why this beats reading the Console by hand: a real site has dozens of templates, and one visit per page rarely covers logged-in states, archive pages or checkout. The reports arrive while you browse normally. Note that 'unsafe-inline' and 'unsafe-eval' are deliberate: this policy exists to flag http:// subresources, not to audit inline scripts, so keep it permissive and delete the mu-plugin once you are done.
If your site lives in a subdirectory, adjust the
report-uripath to/subdir/wp-json/wpth/v1/csp-report, or the endpoint will 404 silently.
Step 2: Read the reports and separate your own URLs from third parties
Tail the log while you click through the pages that show the warning:
tail -f wp-content/debug.log | grep wpth-csp # or, without WP_DEBUG_LOG: tail -f /var/log/nginx/error.log | grep wpth-csp Sort what you see into three buckets. Your own host (http://example.com/wp-content/...) belongs in the database replace below. Third-party hosts that only offer http:// (an old font CDN, an embedded video, a tracking pixel) must be re-embedded over https:// or removed; no search-replace will help. And a handful of blocked-uri values will be inline or eval, which are policy noise you can ignore.
The logger's entries after loading one page that still references http:// URLs (test site: WordPress 7.1.3, PHP 8.2):
$ grep wpth-csp wp-content/debug.log [11-Nov-2026 13:38:52 UTC] [wpth-csp] http://localhost/wp-content/uploads/2019/04/team.jpg on http://localhost/?pagename=about-us [11-Nov-2026 13:38:52 UTC] [wpth-csp] http://localhost/wp-content/themes/twentytwentyfive/assets/fonts/manrope/Manrope-VariableFont_wght.woff2 on http://localhost/?pagename=about-us [11-Nov-2026 13:38:52 UTC] [wpth-csp] http://localhost/wp-content/themes/twentytwentyfive/assets/fonts/fira-code/FiraCode-VariableFont_wght.woff2 on http://localhost/?pagename=about-us [11-Nov-2026 13:38:52 UTC] [wpth-csp] http://localhost/wp-includes/js/dist/script-modules/interactivity/index.min.js?ver=efaa5193bbad9c60ffd1 on http://localhost/?pagename=about-us [11-Nov-2026 13:38:52 UTC] [wpth-csp] http://fonts.example-cdn.net/pixel.gif on http://localhost/?pagename=about-us [11-Nov-2026 13:38:52 UTC] [wpth-csp] http://localhost/wp-includes/js/dist/script-modules/block-library/navigation/view.min.js?ver=1bf28ded04f9f188bdcb on http://localhost/?pagename=about-us [11-Nov-2026 13:38:52 UTC] [wpth-csp] http://localhost/favicon.ico on http://localhost/?pagename=about-us [11-Nov-2026 13:38:52 UTC] [wpth-csp] http://localhost/wp-includes/js/wp-emoji-release.min.js?ver=7.1.3 on http://localhost/?pagename=about-us Step 3: Replace the URLs in the database with a serialisation-aware WP-CLI run
Page builders store their layout as a serialised PHP array. Traversing that array naively corrupts it, because a serialised string records its own byte length: change http to https and every nested string's length declaration becomes wrong, which is why broken widgets appear after a bad replace. wp search-replace handles this properly: it unserialises, walks the structure, replaces, and re-serialises with correct lengths.
Take a backup first, then dry-run:
wp db export backup-before-https.sql # 1. Inventory only — nothing is written. wp search-replace 'http://example.com' 'https://example.com' \ --all-tables-with-prefix \ --precise \ --dry-run \ --report-changed-only Read the per-table counts before continuing. If a builder table or a custom plugin table sits outside your prefix, it will not appear: run it separately. Then commit the change:
wp search-replace 'http://example.com' 'https://example.com' \ --all-tables-with-prefix \ --precise \ --recurse-objects \ --skip-columns=guid \ --report-changed-only \ --log # Tables that ignore the site prefix: wp search-replace 'http://example.com' 'https://example.com' custom_builder_data \ --precise --log The flags matter. --precise forces a PHP-side replace per row (slower, but it validates serialised data instead of doing a raw SQL string swap). --recurse-objects descends into nested arrays and objects. --skip-columns=guid leaves post GUIDs alone: changing them re-identifies every post to feed readers and can duplicate entries in some aggregators. Finally, search for protocol-relative leftovers: //example.com inherits the page protocol, so it is usually safe, but a hardcoded http:// hidden inside base64 or JSON-escaped meta (http:\/\/example.com) will not match the plain pattern. Run one more pass for the escaped form if the reports persist.
Step 4: Catch http:// URLs baked into theme CSS and builder JSON
The database is only half the surface. A stylesheet fetched from disk cannot be filtered by PHP, so grep the theme and child theme first and fix those files by hand: ideally by switching to relative paths or home_url() for assets generated in PHP:
grep -rn "http://example.com" wp-content/themes/my-theme \ --include="*.css" --include="*.js" --include="*.json" --include="*.php" For everything that is generated at render time (Customiser CSS, shortcode output, widget text, builder markup stored in postmeta) a narrow filter is a defensible stopgap while you clean the source data. It targets your own host only, and handles the JSON-escaped slash form builders produce:
<?php /** * Rewrites this site's own http:// URLs at render time, * including JSON-escaped slashes used by page builders. */ function wpth_upgrade_own_host( $value ) { if ( ! is_string( $value ) || '' === $value ) { return $value; } $host = wp_parse_url( home_url(), PHP_URL_HOST ); $needles = array( 'http://' . $host, 'http:\\/\\/' . $host, ); $replacements = array( 'https://' . $host, 'https:\\/\\/' . $host, ); return str_replace( $needles, $replacements, $value ); } add_filter( 'the_content', 'wpth_upgrade_own_host', 99 ); add_filter( 'the_excerpt', 'wpth_upgrade_own_host', 99 ); add_filter( 'widget_text_content', 'wpth_upgrade_own_host', 99 ); add_filter( 'wp_get_custom_css', 'wpth_upgrade_own_host', 99 ); Keep it on a hook layer, never on ob_start(). After the database replace, regenerate each builder's compiled assets from its own admin screen: Elementor's Regenerate CSS & Data, Divi's static CSS cache, WPBakery's shortcode cache: otherwise an old compiled stylesheet can keep serving http:// font URLs even though the database is clean.
Behind a proxy or CDN, is_ssl() lies and keeps the bug alive
If TLS terminates at Cloudflare, an AWS load balancer or an nginx reverse proxy, PHP sees a plain HTTP connection to the origin. is_ssl() returns false, and every plugin that builds URLs conditionally (many form, gallery and page-builder modules do) keeps emitting http://. Tell WordPress to trust the forwarded protocol, but only when your proxy is the thing setting that header; trusting it unconditionally lets a client spoof https:
<?php // wp-config.php — trust the proxy's forwarded protocol header. if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] ) { $_SERVER['HTTPS'] = 'on'; } define( 'FORCE_SSL_ADMIN', true ); Cloudflare's "Automatic HTTPS Rewrites" can clean up links inside HTML, but it cannot rewrite URLs constructed by JavaScript or stored in JSON, and it masks the underlying problem during future migrations. Leave it off while you diagnose, and rely on it afterwards only as belt-and-braces. Also check WP_HOME/WP_SITEURL in wp-config.php: a stale http:// constant overrides the database and silently regenerates insecure links on every request.
My tip · Md. Zubaer Ahammed
Run the search-replace with --dry-run first and read the per-table counts, and export the database before the real run. It is the one step in this guide you cannot undo without a backup.
A short verification pass that proves the fix is complete
- Hard-reload each affected template with the browser cache disabled, then filter the Network tab by
http://: the list should be empty. - View source and search for
http://.http://schema.organdhttp://www.w3.orgnamespaces are harmless; anything else is suspect. - Fetch
/wp-json/wp/v2/posts?per_page=1and/feed/and search both for http://: REST and RSS bypass most page-level fixes. - Open each builder's edit screen as an administrator; builder canvases render outside the front-end theme and expose residual http:// meta.
- Remove the mu-plugin reporter, purge page cache, CDN cache and object cache, then repeat step 1.
If the mixed content appeared after a domain change rather than a switch to SSL, the same search-replace rules apply, and replacing old URLs after a WordPress domain change covers the serialised-data traps in more detail.
Once the reports are quiet, a permanent enforced policy of upgrade-insecure-requests is a sensible next layer: it tells browsers to fetch any remaining http:// subresource over https:// automatically, catching the URL a content editor pastes next month before it ever breaks the padlock. Add it alongside your existing security headers, test on staging first, and keep the original report-only file in version control so you can re-enable logging the moment the warning returns.
Originally published on WP Tuts Hub.