WordPress mixed content: site uses HTTPS but assets load over HTTP
Your site runs on HTTPS, but images, scripts or stylesheets still load over HTTP. Browsers block these “mixed content” requests, and in some cases they even make Gutenberg fail to save. The root cause is almost always a hardcoded http:// URL somewhere in wp-config.php, the database or a plugin.
Problem: After moving a WordPress site to HTTPS, the browser shows a “mixed content” warning and the padlock icon disappears because some assets are still referenced with http:// URLs.
Step 1. Check wp-config.php
Open the browser console. If you see a Mixed Content warning, check wp-config.php first. A common mistake is defining WP_SITEURL or WP_HOME with a hardcoded http:// scheme:
// Wrong: forces HTTP URLs for all assets on the HTTPS site.
if ( $_SERVER['SERVER_NAME'] === 'example.com' ) {
define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/' );
} else {
define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/sitename/' );
}
// Correct: HTTPS on the live site, HTTP on the local copy.
if ( $_SERVER['SERVER_NAME'] === 'example.com' ) {
define( 'WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] . '/' );
define( 'WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/' );
} else {
define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/sitename/' );
define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/sitename/' );
}
Step 2. Replace HTTP URLs in the database
If the URLs in wp-config.php look fine, the problem is in the database: post content, widgets and options still contain the old URLs. Use WP-CLI’s search-replace to fix them all at once. It handles serialized data correctly, unlike a plain SQL REPLACE():
# Dry run first: preview what would change wp search-replace 'http://example.com' 'https://example.com' --dry-run --skip-columns=guid # Apply the replacement wp search-replace 'http://example.com' 'https://example.com' --skip-columns=guid
The guid column is skipped because it is an identifier for feed readers, not a link, and should not change.
Step 3. Fix assets added by plugins and themes
If a plugin or theme enqueues an asset with a hardcoded http:// URL, rewrite it to HTTPS by handle:
add_filter( 'script_loader_src', 'helloadmin_force_https_src', 10, 2 );
add_filter( 'style_loader_src', 'helloadmin_force_https_src', 10, 2 );
function helloadmin_force_https_src( $src, $handle ) {
if ( 'some-plugin-script' === $handle ) {
$src = set_url_scheme( $src, 'https' );
}
return $src;
}
Only do this for resources that are actually available over HTTPS; check the URL in the browser first.
Why Gutenberg fails to save
Gutenberg saves posts through the REST API. If the request is blocked as mixed content, or redirected from HTTP to HTTPS (a redirect turns the POST into a GET), the save fails with a generic “Updating failed” message. Fixing the URLs fixes the editor as well.