I’ve run into this same annoyance as well and after too many times clicking a link and ending up in the wrong environment, I wrote a filter to replace the stored link with the current home_url()
+ the desired path. I use the WP_HOME
and WP_SITEURL
constants in wp-config.php
(which is gitignored) so home_url()
is always pointing to the right place.
add_filter('wp_nav_menu_objects', function ($menu_items) {
foreach ($menu_items as $i => $menu_item) {
$item_path = parse_url($menu_item->url, PHP_URL_PATH);
$menu_item->url = home_url() . $item_path;
$menu_items[$i] = $menu_item;
}
return $menu_items;
});