PHP code example of themeplate / navwalker

1. Go to this page and download the library: Download themeplate/navwalker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

themeplate / navwalker example snippets


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

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;
	}
}