-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap-navbar.php
98 lines (65 loc) · 2.08 KB
/
bootstrap-navbar.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* @link https://github.com/mathewcallaghan/bootstrap-navbar
* @since 1.0.0
* @package Bootstrap_Navbar
*
* @wordpress-plugin
* Plugin Name: Bootstrap Navbar
* Plugin URI: https://github.com/mathewcallaghan/bootstrap-navbar
* Description: Make a Wordpress menu compatible with Bootstrap 4 (requires Bootstrap 4).
* Version: 1.0.1
* Author: Mathew Callaghan
* Author URI: https://mathew.callaghan.xyz/
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
* Text Domain: bootstrap-navbar
* Domain Path: /languages
*/
if ( ! defined( 'WPINC' ) ) {
die;
}
//dropdown-menu
function submenu_css( $classes, $args, $depth ) {
$classes[] = 'dropdown-menu';
return $classes;
}
add_filter( 'nav_menu_submenu_css_class', 'submenu_css', 10, 3 );
//nav-item
function navitem_css( $classes, $item, $args, $depth ) {
foreach ( $item->classes as $value ) {
if ( 'menu-item' === $value && $depth == 0 ) {
$classes[] = 'nav-item';
}
elseif ( 'menu-item-has-children' === $value || 'page_item_has_children' === $value ) {
$classes[] = 'dropdown';
}
elseif ( 'current-menu-item' === $value ) {
$classes[] = 'active';
}
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'navitem_css', 10, 4 );
//nav-link
function navlink_css( $atts, $item, $args, $depth) {
foreach ( $item->classes as $value ) {
if ( 'menu-item' === $value && $depth == 0 ) {
$atts['class'] = 'nav-link';
}
if ( 'disabled' === $value ) {
$atts['href'] = '';
}
if ( 'menu-item-has-children' === $value || 'page_item_has_children' === $value ) {
$atts['class'] = 'nav-link dropdown-toggle';
$atts['data-toggle'] = 'dropdown';
$atts['aria-haspopup'] = 'true';
$atts['aria-expanded'] = 'false';
}
if ( 'menu-item' === $value && $depth >= 1 ) {
$atts['class'] = 'dropdown-item';
}
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'navlink_css', 10, 4 );