├── .editorconfig ├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── composer.lock ├── src └── WordPressMenuClasses.php └── wordpress-menu-classes.sublime-project /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.php] 15 | indent_size = 4 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore node dependency directories 2 | node_modules/ 3 | vendor 4 | 5 | # ignore log files and databases 6 | *.log 7 | *.sql 8 | *.sqlite 9 | *.sublime-workspace -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 davidwebca 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WordPress Menu Classes 2 | 3 | Allow adding custom classes to WordPress li, a and submenus at different depths. Perfect for TailwindCSS and AlpineJS usage. 4 | 5 | This package adds WordPress filters to allow custom arguments to wp_nav_menu to, in turn, allow custom classes to every element of a menu. You can apply a class only to certain depth of your menu as well. 6 | 7 | This is probably as far as you can go without creating a custom nav walker which I've always hated to do. 8 | 9 | ## Requirements 10 | 11 | - [Composer](https://getcomposer.org/download/) 12 | 13 | ## Installation 14 | 15 | Install via Composer: 16 | 17 | ```bash 18 | $ composer require davidwebca/wordpress-menu-classes 19 | ``` 20 | 21 | If your theme already uses composer, the filters will be automatically added thanks to the auto-loading and auto-instantiating class. Otherwise, add this to the top of your functions.php: 22 | 23 | ```php 24 | require_once 'vendor/autoload.php'; 25 | ``` 26 | 27 | And if you're looking for a standalone file you want to add to your theme, look for src/WordPressMenuClasses.php in this repository. 28 | 29 | ## Instructions 30 | 31 | The filters use the depth argument given by WordPress which is an index, thus starts with level 0 (zero). 32 | 33 | Here's a list of the custom arguments you can pass to wp_nav_menu that are supported by this package : 34 | 35 | - ```a_atts``` or ```a_atts_$depth``` or ```a_atts_order_$order``` 36 | - ```a_class``` or ```a_class_$depth``` or ```a_class_order_$order``` 37 | - Add any attribute or class to `````` elements 38 | 39 | - ```li_atts``` or ```li_atts_$depth``` or ```li_atts_order_$order``` 40 | - ```li_class``` or ```li_class_$depth``` or ```li_class_order_$order``` 41 | - Add any attribute or class to ```
  • ``` elements 42 | 43 | - ```submenu_atts``` or ```submenu_atts_$depth``` 44 | - ```submenu_class``` or ```submenu_class_$depth``` 45 | - Add any attribute or class to submenu ```