Skip to content

Instantly share code, notes, and snippets.

@farik92
Last active August 5, 2019 19:45
Show Gist options
  • Select an option

  • Save farik92/c0a50d532a92ab64a8e0ee5709387c2d to your computer and use it in GitHub Desktop.

Select an option

Save farik92/c0a50d532a92ab64a8e0ee5709387c2d to your computer and use it in GitHub Desktop.
<?php
//Удаляем ссылку у текущего пункта меню WordPress
function wp_nav_menu_no_current_link( $atts, $item, $args, $depth ) {
if ( $item->current ) $atts['href'] = '';
return $atts;
}
add_action( 'nav_menu_link_attributes', 'wp_nav_menu_no_current_link', 10, 4 );
//Если есть необходимость применить это только для конкретного меню, то код будет таким:
function wp_nav_menu_no_current_link( $atts, $item, $args, $depth ) {
if ( $args->theme_location == 'menu_name' ) {
if ( $item->current ) $atts['href'] = '';
}
return $atts;
}
add_action( 'nav_menu_link_attributes', 'wp_nav_menu_no_current_link', 10, 4 );
//Здесь menu_name — это идентификатор, который указывается в функции register_nav_menu() и в параметре theme_location функции wp_nav_menu().
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment