How to Change from www to non-www WordPress links

Back in the days it was pretty common to use www.example.com but that’s not popular anymore.

People don’t want to type longer words. For this reason it’s good to omit the www. prefix.

Approach 1: update from WordPress UI

If the site is pretty new (set up in the last 24h) you can go to WP-Admin > Settings > General and then remove the www. prefix from WordPress Address and Site Address.

Keep in mind that this will change the WordPress links but not any existing links found in the content.

Important: do NOT be temped to change WordPress folder or any other paths using the approach above because you WILL be locked out of WordPress and will need to contact support or hire us to restore the previous settings.

Approach 2: using wp-cli

if you or your developer have ssh access to the server you can run the following command to change the links.

wp search-replace 'www.example.com' 'example.com' --skip-plugins --skip-themes --precise --recurse-objects --skip-columns=guid --skip-themes 2>&1

it will run a command to replace the occurrences of your old site so it’s without www. It would be a slower so WP-CLI has to decode so called serialized data but it will be worth it.

The plugins and themes are not loaded because some of them do not handle cases when they are run from the command line.

Leave a Comment

Your email address will not be published. Required fields are marked *