Skip to content

Instantly share code, notes, and snippets.

@1Kakady1
Last active April 26, 2018 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1Kakady1/917daca6993b9cc781872797c9b96dd9 to your computer and use it in GitHub Desktop.
Save 1Kakady1/917daca6993b9cc781872797c9b96dd9 to your computer and use it in GitHub Desktop.
(Can and block)
//setting the class of the menu item
add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
function special_nav_class($classes){
if(is_page(4)){
$classes[] = 'active';
}
return $classes;
}
//We make each menu active
class Custom_Walker_Nav_Menu_top extends Walker_Nav_Menu
{
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$is_current_item = '';
if(array_search('current-menu-item', $item->classes) != 0)
{
$is_current_item = ' class="active"';
}
echo '<li'.$is_current_item.'><a href="'.$item->url.'">'.$item->title;
}
function end_el( &$output, $item, $depth = 0, $args = array() ) {
echo '</a></li>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment