Software Developer

Change Custom Menu Links in WP from HTTP to HTTPS via MySQL

This is useful if you created custom menu links for your WordPress menu, in the WordPress admin –> “Appearance” –> “Menus”, and now you need to change the link URLs from “http” to “https” because you are now using an SSL certificate. These are the MySQL statements that let you make those changes directly in the database, for example, via phpMyAdmin.

Note: This will change http URLs for the custom menu links that point to your site, not custom menu links that point to other sites.

The alternative would be for you to go into “Appearance” –> “Menus” and manually change each link URL to “https”. If you have a multisite network with many custom links, these MySQL statements will save you a bunch of time. There are 2 examples below, one for WordPress single site, and one for multisite.

This will change all of your custom menu links which you created in “Appearance” –> “Menus” –> Custom Links. It will change their beginning from “http:” to “https:” but only for URLs on your own site, not external sites (although, you could modify the queries below, as needed).

WP Single Site

This makes the change on WordPress single site.

You must change DB_NAME to your own WordPress database name. Change www.yoursite.com to your own site, and if you didn’t use the www when you created your Custom Menu Links, then leave out the www here. For example, some people just use http://yoursite.com, without the www.

UPDATE `DB_NAME`.`wp_postmeta` SET `meta_value` = replace( meta_value, "http://www.yoursite.com", "https://www.yoursite.com" ) WHERE `wp_postmeta`.`meta_key` = '_menu_item_url';

WP Multisite Network

The following makes the change on all sites of a WordPress Multisite network. Each line does it for one site. If you have less than 8 sites, delete the extra lines and leave only up the number of sites that you have. If you have more than 8 sites in your WordPress network, add one line for each extra site, while making sure to update the number in both places on the new lines.

On each line below, you must change DB_NAME to your own WordPress database name. Change www.yoursite.com to your own site, and if you didn’t use the www when you created your Custom Menu Links, then leave out the www here. For example, some people just use http://yoursite.com, without the www.

UPDATE `DB_NAME`.`wp_postmeta` SET `meta_value` = replace( meta_value, "http://www.yoursite.com", "https://www.yoursite.com" ) WHERE `wp_postmeta`.`meta_key` = '_menu_item_url';

UPDATE `DB_NAME`.`wp_2_postmeta` SET `meta_value` = replace( meta_value, "http://www.yoursite.com", "https://www.yoursite.com" ) WHERE `wp_2_postmeta`.`meta_key` = '_menu_item_url';

UPDATE `DB_NAME`.`wp_3_postmeta` SET `meta_value` = replace( meta_value, "http://www.yoursite.com", "https://www.yoursite.com" ) WHERE `wp_3_postmeta`.`meta_key` = '_menu_item_url';

UPDATE `DB_NAME`.`wp_4_postmeta` SET `meta_value` = replace( meta_value, "http://www.yoursite.com", "https://www.yoursite.com" ) WHERE `wp_4_postmeta`.`meta_key` = '_menu_item_url';

UPDATE `DB_NAME`.`wp_5_postmeta` SET `meta_value` = replace( meta_value, "http://www.yoursite.com", "https://www.yoursite.com" ) WHERE `wp_5_postmeta`.`meta_key` = '_menu_item_url';

UPDATE `DB_NAME`.`wp_6_postmeta` SET `meta_value` = replace( meta_value, "http://www.yoursite.com", "https://www.yoursite.com" ) WHERE `wp_6_postmeta`.`meta_key` = '_menu_item_url';

UPDATE `DB_NAME`.`wp_7_postmeta` SET `meta_value` = replace( meta_value, "http://www.yoursite.com", "https://www.yoursite.com" ) WHERE `wp_7_postmeta`.`meta_key` = '_menu_item_url';

UPDATE `DB_NAME`.`wp_8_postmeta` SET `meta_value` = replace( meta_value, "http://www.yoursite.com", "https://www.yoursite.com" ) WHERE `wp_8_postmeta`.`meta_key` = '_menu_item_url';

By

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]