rename navigation menu label in wordpress theme by code

Maybe try filtering just the menu items you want when they get printed back on the front end. You can do that in functions.php

Here you can filter the HTML list content for navigation menus.
https://developer.wordpress.org/reference/hooks/wp_nav_menu_items/

After some talk, give this a try and then call your lo() where you need it:

function lo() { 
  add_filter( 'wp_nav_menu_items', 'dynamic_label_change', 10, 2 ); 

  function dynamic_label_change( $items,$args) { 

    if($args->theme_location == 'primary'){ 
      $items = str_replace("Categories", "new_string", $items); 
      $items = str_replace("Latest Offers", "another_new_string", $items); 
    } 
    return $items; 
  } 
} 

Leave a Comment