Hi @navasahmed
I need to discuss this with my development team. Hopefully, I will get back to you with the solution.
Regards,
Sumit
Hi @sumitsanadhya
Thanks for the quick reply :).
Could you please make it fast. we need to solve the issue ASAP. hopefully we will get the solution as soon as possible
Thanks.
Hi @navasahmed
You can use nav_menu_link_attributes filter to update or change the attribute or link like classes, title, target, href etc.
You can check our code in v4.0.0/inc/classes/class-walker.php on line 140
// Set attributes on menu item link.
$atts = array();
$atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
$atts['target'] = ! empty( $item->target ) ? $item->target : '';
$atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
$atts['class'] = 'rmp-menu-item-link';
$atts['role'] = 'menuitem';
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
You can use a filter hook-like
add_filter( 'nav_menu_link_attributes', 'change_page_menu_classes', 10, 4 );
function change_page_menu_classes( $atts, $item, $args, $depth )
{
global $post;
if ( 'projects' === get_post_type($post) && 299 === intval( $item->ID ) )
{
//add your code here
$atts['class'] = str_replace( 'rmp-menu-item-link', 'rmp-menu-item-link current-menu-item', $atts['class']);
}
return $atts;
}
Let me know if you need more help.
Regards,
sumit
Hello @sumitsanadhya
Thank you for the snippet. It works for the menu link. Adding an extra class to “li” or “div” is what I need to do. The new class does not need to be added to anchor tags. Please help me to add the new class to “li” or “div”.
Thank you in advance
Hello @sumitsanadhya
Any updates on above request. waiting for your reply.
Thanks
Hi @navasahmed
Let me discuss this with the technical team. I will get back to you soon.
Regards,
sumit
Hi @navasahmed
Yesterday we release a new version of RM which is v 4.1.11 so please update. you can use the below-given code.
add_filter( 'rmp_nav_item_class', 'change_page_menu_classes', 10, 2 );
function change_page_menu_classes( $class_names, $item )
{
global $post;
if ( 'projects' === get_post_type($post) && 299 === intval( $item->ID ) )
{
//add your code here
$class_names = str_replace( 'rmp-menu-item', 'rmp-menu-item current-menu-item', $class_names);
}
return $class_names;
}
Let me know if you need more help.
Regards,
sumit