Last active
December 6, 2016 10:35
-
-
Save lomboboo/a31550b228bd490b0de93b3730a93ce0 to your computer and use it in GitHub Desktop.
Creating custom menu template with registering location
This file contains hidden or 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
//Usage: creating custom menu in Wordpress panel with name as $menu_name value | |
// Next: calling right_custom_menu function where custom menu is needed as follows =>> if (function_exists(right_custom_menu())) right_custom_menu(); | |
function right_menu_position() { | |
register_nav_menu('nav_right',__( 'Prawe menu' )); | |
} | |
add_action( 'init', 'right_menu_position' ); | |
function right_custom_menu() { | |
$menu_name = 'nav_right'; // specify custom menu slug | |
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 = '<div class="right-menu-wrapper">' ."\n"; | |
foreach ((array) $menu_items as $key => $menu_item) { | |
$title = $menu_item->title; | |
$url = $menu_item->url; | |
$target = $menu_item->target; | |
$menu_list .= "\t\t\t\t\t". '<div class="toggle"><p><a href="'. $url .'" target="'.$target.'">'. $title .'</a></p></div>' ."\n"; | |
} | |
$menu_list .= "\t\t\t". '</div>' ."\n"; | |
} else { | |
// $menu_list = '<!-- no list defined -->'; | |
} | |
echo $menu_list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment