Last active
September 24, 2017 08:30
-
-
Save faisalhmohd/0915cf2d1868cecd6b8fdbe02af8f241 to your computer and use it in GitHub Desktop.
Add a custom menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Custom Menu | |
add_filter( 'init', 'register_primary_menu'); | |
function register_primary_menu() { | |
register_nav_menu('nav-primary',__( 'Navigation Primary' )); | |
} | |
function custom_primary_menu() { | |
$menu_name = 'nav-primary'; | |
if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) { | |
$menu = wp_get_nav_menu_object($locations[$menu_name]); | |
$menu_items = wp_get_nav_menu_items($menu->term_id); | |
$menu_list = '<ul>' ."\n"; | |
foreach ((array) $menu_items as $key => $menu_item) { | |
$title = $menu_item->title; | |
$url = $menu_item->url; | |
$menu_list .= '<li><a '; | |
$menu_list .= ' href="'. $url .'">'. $title .'</a> <i class="fa fa-plus-square" aria-hidden="true"></i></li>' ."\n"; | |
} | |
$menu_list .= '<li><form method="get" action="/search/"><input type="text" name="q" placeholder="Search Next Level.."/></form></li>'; | |
$menu_list .= '</ul>' ."\n"; | |
} else { | |
$menu_list = 'Please set up your menu'; | |
} | |
echo $menu_list; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment