WordPress切换HTTPS后图片仍为HTTP引发混合内容问题的解决方法
Hey there, let's tackle that mixed content error you're seeing after switching your WordPress site to HTTPS. Those HTTP image URLs are causing the browser to throw warnings, but we've got several solid ways to fix this:
Before diving into image fixes, double-check your core WordPress settings—this is the foundation:
- Head to Settings > General in your WordPress dashboard.
- Update both WordPress Address (URL) and Site Address (URL) from
http://yourdomain.comtohttps://yourdomain.com. - Hit "Save Changes" and you're good to go here.
Most of your old images are referenced in post content and metadata with HTTP. Here are two ways to update them en masse:
Option A: Use a Plugin (No-Code, Safe for Beginners)
Plugins like Better Search Replace or Velvet Blues Update URLs are made for this exact task:
- Install and activate your chosen plugin from the WordPress plugin repository.
- For Better Search Replace:
- In the plugin's settings, enter
http://yourdomain.comin the "Search for" field, andhttps://yourdomain.comin "Replace with". - Select all database tables (or at least
wp_posts,wp_postmeta, andwp_options—adjust thewp_prefix if your site uses a different one). - Start with a "dry run" to preview changes without modifying anything. If the preview looks correct, uncheck the dry run box and run the replacement.
- In the plugin's settings, enter
Option B: Run SQL Queries (Advanced Users)
If you're comfortable with database tools, use phpMyAdmin to run these queries (always back up your database first!):
- Log into your hosting control panel and open phpMyAdmin.
- Select your WordPress database.
- Go to the "SQL" tab and execute these commands one by one (replace
yourdomain.comandwp_as needed):UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://yourdomain.com', 'https://yourdomain.com'); UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'http://yourdomain.com', 'https://yourdomain.com'); UPDATE wp_options SET option_value = REPLACE(option_value, 'http://yourdomain.com', 'https://yourdomain.com') WHERE option_name IN ('home', 'siteurl');
Sometimes thumbnail URLs might not update automatically. Fix this with a thumbnail regeneration plugin:
- Install and activate Regenerate Thumbnails.
- Go to Tools > Regenerate Thumbnails and click "Regenerate All Thumbnails". This will update every image size to use HTTPS.
To prevent future mixed content issues, add a rule to your .htaccess file to redirect all HTTP requests to HTTPS:
- Access your site's root folder via FTP or your hosting file manager.
- Edit the
.htaccessfile and add these lines at the top:
Alternatively, use the Really Simple SSL plugin—it automates this setup and helps detect remaining mixed content.<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] </IfModule>
Occasionally, themes or plugins might have hardcoded HTTP image URLs. Here's how to fix that:
- Use the Theme Editor under Appearance (or FTP) to search your theme files for
http://yourdomain.com—replace any matches withhttps://. - Do the same for plugins: check their files for hardcoded URLs. If you find any, update the plugin first (if it's outdated), or modify the code (make a backup before editing!).
After completing these steps, clear your browser cache and any WordPress caching plugins you use. Then, open your site in Chrome (hit F12 to open DevTools) and check the Console tab for any remaining mixed content errors—they should be gone!
内容的提问来源于stack exchange,提问作者Daniel Washington Ignacio

