Skip to main content
28 votes
Accepted

How to modify navigation menu of the "My Account" page in WooCommerce

For that, you do not need to modify the woocommerce/templates/myaccount/navigation.php. The best way to customize the "My Account" navigation menu items is to use: woocommerce_account_menu_items ...
ClemC's user avatar
  • 1,985
27 votes
Accepted

Add custom classes to anchor in wp_nav_menu

You can do this with the nav_menu_link_attributes filter. add_filter( 'nav_menu_link_attributes', 'wpse156165_menu_add_class', 10, 3 ); function wpse156165_menu_add_class( $atts, $item, $args ) { ...
cjbj's user avatar
  • 15k
14 votes

How to Add <span> to Each Menu Link with link text to data-attr?

Since version 4.4.0 the 'nav_menu_item_args' filter was added. This allows you to set 'link_before' and 'link_after' attributes for each item. add_filter('nav_menu_item_args', function ($args, $item, ...
Daren Zammit's user avatar
8 votes

Displaying Logged-In User Name in Wordpress Menu

The code: function give_profile_name($atts){ ... } gives a warning. Better is: function give_profile_name(){ ... } And it is better to detect if the user is logged in or not. Like so: function ...
Eutychus Mak's user avatar
8 votes

How to modify navigation menu of the "My Account" page in WooCommerce

Well customizing Woocommerce account and adding new items comes in a few steps, First Step: Create Links: You should use woocommerce_account_menu_items filter to modify existing menu items or adding ...
Amin Abdolrezapoor's user avatar
7 votes

Get the children of the parent category

Use the code below in your archive.php file. This code will help you: $term = get_queried_object(); $children = get_terms( $term->taxonomy, array( 'parent' => $term->term_id, '...
Violla Queue's user avatar
7 votes

How to add menu support to a theme?

Put this pretty much anywhere (ie. functions.php) add_theme_support( 'menus' );
Joel M's user avatar
  • 427
6 votes

Remove current_page_parent nav class from blog index when in CPT

The current answer is great but it assumes the title of blog's navigation item is "Blog". This could cause problems if the a user ever modifies the nav item in WordPress. The following code is ...
richk's user avatar
  • 61
6 votes

Displaying Logged-In User Name in Wordpress Menu

No shortcode needed add_filter( 'wp_nav_menu_objects', 'my_dynamic_menu_items' ); function my_dynamic_menu_items( $menu_items ) { foreach ( $menu_items as $menu_item ) { if ( strpos($...
Manu Lebranders's user avatar
6 votes
Accepted

PHP 7 - Class Method Compatibility Issue

You must have the same function arguments in functions on class inheritance. So replace function update() with update($new_instance, $old_instance) in your code
Anton Lukin's user avatar
6 votes
Accepted

Add class to active top level (grandparent) menu item

Styling the top-level item if it's active or a child is active is possible with pure CSS. Use the child selector, >, from the top: .sidebar-navigation > ul > .current-menu-item, .sidebar-...
Jacob Peattie's user avatar
5 votes
Accepted

Get menus created with menu editor?

Maybe this helps : function get_all_wordpress_menus(){ return get_terms( 'nav_menu', array( 'hide_empty' => true ) ); } get_registered_nav_menus only gets the theme's menu's and not the ...
CompactCode's user avatar
5 votes

Move WP Admin Bar

The admin bar is hooked to wp_footer. So … remove_action( 'wp_footer', 'wp_admin_bar_render', 0 ); … will remove it from there. And then you can register it for a custom hook with: add_action( '...
fuxia's user avatar
  • 107k
4 votes

Add custom classes to anchor in wp_nav_menu

I have solution to add class to anchor tag. 1: Step: add this in functions.php function add_additional_class_on_a($classes, $item, $args) { if (isset($args->add_a_class)) { $classes['...
Mohammad Ayoub Khan's user avatar
4 votes

wp_nav_menu: check if the list item has children and add a class to anchor link

The other way is very simple and may be useful for some people /** * Custom Nav Classes * https://v123.tw */ add_filter('nav_menu_css_class' , 'v123_nav_class' , 10 , 2 ); function v123_nav_class ($...
Ann's user avatar
  • 141
4 votes

How to add text before WordPress menu item href

You'll want to use the following filter: nav_menu_link_attributes Example: function filter_nav_menu_link_attributes($atts, $item, $args) { if ( isset($args->theme_location) && $args-...
Adam's user avatar
  • 16.5k
4 votes
Accepted

Third level navigation class

You don't need to write your custom Walker for that... Let's take a look on built-in Walker_Nav_Menu. You'll find this function: public function start_lvl( &$output, $depth = 0, $args = array() )...
Krzysiek Dróżdż's user avatar
4 votes
Accepted

add another html tag after li element in wp_nav_menu

When using wp_nav_menu() you can exclude the <ul> tag by setting the items_wrap to only include the list items (%3$s), then you can add your own <li> before or after that, and wrap it with ...
Jacob Peattie's user avatar
3 votes

Navigation (wp_nav_menu) refuses to nest within parent element

'echo' => true needs to be 'echo' => false in your wp_nav_menu array for it to nest. From the docs you'll find 'echo' (bool) Whether to echo the menu or return it. Default true. so what's ...
FellowTraveler's user avatar
3 votes

Remove current_page_parent nav class from blog index when in CPT

Ok both answers are not very elegant because you have to enter the CPTs name manually. Here is a simple drop in snippet. It is pretty much copied from here so kudos to that site. This snippet removes ...
GDY's user avatar
  • 448
3 votes
Accepted

Export navigation menu

WordPress has an Import/Export tool, but it doesn't works with nav menus only, the "All Content" option will export the menus too, but with everything else that is in your site (including posts/pages ...
David Lee's user avatar
  • 3,941
3 votes
Accepted

remove specific classes from menu items

add_filter('nav_menu_css_class', 'special_nav_class', 10, 2); function special_nav_class($classes, $item){ if(($key = array_search('fa', $classes)) !== false) { unset($classes[$key]); }...
Farhad Sakhaei's user avatar
3 votes
Accepted

how to change Wordpress menu markup/classes

Changing the CSS is the simplest way to apply your desired styles. Another alternative, as Jack mentioned, is to create a custom walker. The Codex has a good overview. The third option is a happy ...
WebElaine's user avatar
  • 9,664
3 votes

Add Bootstrap dropdown class to a nav menu

The easiest way to do this is to use an off-the-shelf solution. There is a WP_Bootstrap_Navwalker class which extends WordPress' native Walker_Nav_Menu class and makes your Navigation Menus ready for ...
Max Yudin's user avatar
  • 6,368
3 votes
Accepted

Why is 'nav_menu_item_args' filter's $item argument empty?

Filters (and actions) need to be declared with the number of arguments accepted by the callback; it is the fourth parameter of add_filter() (default 1): add_filter( 'nav_menu_item_args', '...
cybmeta's user avatar
  • 20.6k
3 votes
Accepted

Return only top-level navigation items from a menu using wp_get_nav_menu_items

Let's take a look at wp_get_nav_menu_items code reference. It takes two parameters: $menu - (int|string|WP_Term) (Required) Menu ID, slug, name, or object, $args - (array) (Optional) Arguments to ...
Krzysiek Dróżdż's user avatar
3 votes

append to existing parent theme function

No, it doesn't appear to be possible. At least not directly. You can replace functions in parent themes if they are wrapped in: if ( ! function_exists( 'get_nav_markup' ) ) { } Because child themes ...
Jacob Peattie's user avatar
3 votes

Next/Previous Links in same category

previous_post_link takes 5 params, but you use only 2 of them. Let's take a look at other 3: in_same_term (boolean) (optional) Indicates whether previous post must be within the same taxonomy ...
Krzysiek Dróżdż's user avatar
3 votes
Accepted

HTML Bootstrap navigation menu to Wordpress menu using wp_nav_menu

You have to edit the files in: wordpress/wp-content/themes/twentyseventeen/template-parts/navigation/navigation-top.php and then create a custom walker, try to take a look here. Try in this way: &...
benny-ben's user avatar
  • 374

Only top scored, non community-wiki answers of a minimum length are eligible