For most people, switching a WordPress site from http to https is possible with just a few clicks. That’s a big thanks Let’s Encrypt, which is being widely adopted by many popular web hosting companies. That said, there can be a few roadblocks when switching to https. Here are few recommendations when switching to HTTPS everywhere.
Updated URLs to HTTPS within database
I use WP-CLI to update my urls. WP-CLI’s search-replace
handles serialized data and can pretty do everything in one single command.
wp search-replace http://anchor.host https://anchor.host --all-tables
For automating purposes I generally use one of the following scripts which will dynamically find and replace URLs using the current domain used within the database.
#!/bin/bash
#
# Apply SSL using domain without www
#
domain=$(wp option get home)
domain=${domain/http:\/\/www./}
domain=${domain/https:\/\/www./}
domain=${domain/http:\/\//}
domain=${domain/https:\/\//}
wp search-replace http://$domain https://$domain --all-tables --skip-plugins --skip-themes
wp search-replace http://www.$domain https://$domain --all-tables --skip-plugins --skip-themes
wp cache flush
#!/bin/bash
#
# Apply SSL using domain with www
#
domain=$(wp option get home)
domain=${domain/http:\/\/www./}
domain=${domain/https:\/\/www./}
domain=${domain/http:\/\//}
domain=${domain/https:\/\//}
wp search-replace http://$domain https://www.$domain --all-tables --skip-plugins --skip-themes
wp search-replace http://www.$domain https://www.$domain --all-tables --skip-plugins --skip-themes
wp cache flush
Check fonts loading from 3rd party services
Any hard-coded http references to fonts will need to be updated. I recommend looking over header.php and functions.php in the active themes. Also some font services like Typography require you to republish your font kit to a new https location.
Check embeds like Google Maps and YouTube
Anything embedded from a third party site also needs to use https. Using WP-CLI can generally fix these. Here are some common offenders.
wp search-replace http://maps.google.com https://maps.google.com --all-tables
wp search-replace http://www.youtube.com https://www.youtube.com --all-tables
Clear out any manually defined home and siteurl from wp-config.php
This is one of those things which can cause all sorts of redirection problems. While you may have the https URL properly defined under the wp_options
table, the wp-config.php can override those URLs with http URLs. They will look like this and need to be removed.
define( 'WP_SITEURL', 'http://anchor.host' );
define( 'WP_HOME', 'http://anchor.host' );
Find hardcoded references within themes & plugins
Lastly, any hard code reference will also need to be updated. For that I SSH into server, change directories to the WordPress home folder and run the code snippet below. It will prompt to enter a domain and then list out files and line numbers if any http references are found.
function anchor_find_http {
read -p $'\e[31mDomain\e[0m: ' domainname
grep -n -r "http://$domainname" wp-content/ | awk '{ print $1 }'
grep -n -r "http://www.$domainname" wp-content/ | awk '{ print $1 }'
}
anchor_find_http