Asked  1 Year ago    Answers:  5   Viewed   6 times

I'm working on a Wordpress website that has multiple menus set up. I wanted to add custom attributes to the menu items in one of the menus using 'nav_menu_link_attributes', but that adds the attributes to all of the menus. How would I limit this to just one specific menu? I can't find any documentation on this question.

My current code is:

function add_menu_atts($atts){
  $atts['data-inventory-link'] = $atts['href'];
  $atts['data-model'] = $atts['title'];
  return $atts;
}
add_filter('nav_menu_link_attributes', 'add_menu_atts');

 Answers

5

The filter you are using nav_menu_link_attributes supports other arguments as well. You can pass in a 2nd parameter $item and a 3rd parameter $args which contains the item details. Try something like this:

function add_menu_atts($atts, $item, $args){
  // your check for primary menu location
  if( $args->theme_location == 'primary' ) {
    $atts['data-inventory-link'] = $atts['href'];
    $atts['data-model'] = $atts['title'];
  }     

  return $atts;
}
add_filter('nav_menu_link_attributes', 'add_menu_atts', 10, 3);
Thursday, April 1, 2021
 
Saurabh
 
3

You can "remove" the parent theme function with remove_action(). This function removes a function which has been attached to a specified action hook, and is often used to replace functions with a substitute:

remove_action('wp_head', 'aaron_customize_css');

And then add your own function in place of it:

add_action('wp_head', 'aaron_customize_css_child');

So, in all, you'll have something like the following in your child theme:

function aaron_customize_css_child() {
    remove_action('wp_head', 'aaron_customize_css');
    // function contents
}
add_action('wp_head', 'aaron_customize_css_child', 100);
Thursday, April 1, 2021
 
kwichz
 
2

I had the same issue,

I fixed it by making sure /var/lib/php/session folder was set 0777 for permissions, deleted all the session files and did a graceful restart of the server.

Sessions messages went away and voting worked.

Thursday, April 1, 2021
 
Anele
 
2

This should work:

glob('images/N*T.jpg');

Otherwise:

chdir('images');
glob('N*T.jpg');
Saturday, May 29, 2021
 
michele
 
3

You can use insertRange, it will grow the list when adding new elements.

var list = ["1","3","4"];
list.insertRange(0, 1, "0");
list.insertRange(2, 1, "2");
list.forEach((e) => print(e));

You can try it out on the DartBoard here

Sunday, August 15, 2021
 
Shamoon
 
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :