-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp_nav_menu.php
69 lines (57 loc) · 2.13 KB
/
wp_nav_menu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
// First register a menu in functions.php
// Like this-
// Menu register
register_nav_menus(array(
'primary' => __('Primary Menu', 'ieatwp'),
'secondary' => __('Secondary Menu', 'ieatwp')
));
/*
/* Then call the registered menu where you need
/* Like in header.php instead of <ul> </ul>
*/
wp_nav_menu(array(
'theme_location' => 'primary',
'menu_class' => 'navbar navbar-right',
'menu' => ,
'container' => 'div', // if blank then <ul> will the container
'container_class' => 'menu-{menu slug}-container',
'container_id' => ,
'menu_class' => 'menu',
'menu_id' => ,
'before' => ,
'after' => ,
'link_before' => ,
'link_after' => ,
'items_wrap' => '<ul id=\"%1$s\" class=\"%2$s\">%3$s</ul>',
'depth' => 0,
'fallback_cb' => 'ieatwp_default_menu'
));
/*
/* We can put a default menu like below
/* default callback are wp pages and no need any fallback_cb
/* We can use nav Walker too
*/
function ieatwp_default_menu(){ ?>
<ul class="navbar navbar-right">
<li><a href="#section_intro" class="easing">Home</a></li>
<li><a href="#section_about" class="easing">About</a></li>
<li><a href="#section_work" class="easing">Strategy</a></li>
<li><a href="#section_resume" class="easing">Resume</a></li>
<li><a href="#section_portfolio" class="easing">Portfolio</a></li>
<li><a href="#section_services" class="easing">Services</a></li>
<li><a href="#section_contact" class="easing">Contact</a></li>
</ul>
<?php }
// Add class to the ul > li
function alpha_menu_item_class( $classes, $item ) {
$classes[] = "list-inline-item";
return $classes;
}
add_filter( "nav_menu_css_class", "alpha_menu_item_class", 10, 2 );
// Add class to anchor link navigation > ul > li > a
// https://stackoverflow.com/questions/42994156/wordpress-menu-add-class-to-anchors
add_filter( 'nav_menu_link_attributes', function($atts) {
$atts['class'] = "nav-link";
return $atts;
}, 100, 1 );