Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

ThemePlate/NavWalker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ThemePlate NavWalker (Legacy)

Check out the Cleaner package.

Extend / Customize

Simplest (need custom classes)

class Clean_Navbar extends ThemePlate\NavWalker {
	public $classes = array(
		'sub-menu' => 'dropdown-menu',
		'has-sub'  => 'dropdown',
		'active'   => 'active',
		'item'     => 'nav-item',
	);
}

Complex (more control?)

class Clean_Navbar extends ThemePlate\NavWalker {
	public function submenu_css_class( $classes, $args, $depth ) {
		$classes[] = 'sub-' . $depth;

		return $classes;
	}

	public function css_class( $classes, $item, $args ) {
		if ( '_blank' === $item->target ) {
			$classes[] = 'external';
		}

		return $classes;
	}

	public function item_id( $id, $item, $args, $depth ) {
		if ( 10 === $item->ID ) {
			$id = 'i-ten';
		}

		return $id;
	}

	public function link_attributes( $atts, $item, $args, $depth ) {
		if ( in_array( 'icon', $item->classes, true ) ) {
			$atts['aria-hidden'] = true;
		}

		return $atts;
	}
}