Hello there i have a navigation menu in my wordpress theme. The navigation menu has two items. One has the label “home” and the other “categories”. I need to rename the label “home” to something else and the “categories” label name as well. How is this possible on the fly?
Hello there i have a navigation menu in my wordpress theme. The navigation menu has two items. One has the label “home” and the other “categories”. I need to rename the label “home” to something else and the “categories” label name as well. How is this possible on the fly?
Share Improve this question edited Jul 2, 2019 at 18:09 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Jul 2, 2019 at 13:32 stefanosnstefanosn 1339 bronze badges 2- Have you logged into WordPress, in the sidebar go to Appearance > Menus? After you add a link to a menu, you can change the label of the menu item. – ChristopherJones Commented Jul 2, 2019 at 13:46
- I need to change it by code because i have to check for if statement first – stefanosn Commented Jul 2, 2019 at 13:47
1 Answer
Reset to default 1Maybe 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/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;
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745350969a4623829.html
评论列表(0条)