diff --git a/README.md b/README.md
index d039417..7d7a84a 100644
--- a/README.md
+++ b/README.md
@@ -28,59 +28,67 @@ Download the [latest release](https://github.com/Log1x/navi/releases/latest) `.z
## Usage
-Check out the [**examples**](examples) folder to see how to use Navi in your project.
-
-### Basic Usage
+Building your menu can be done by passing your menu location to `Navi::make()->build()`:
```php
-build('primary_navigation');
+$menu = Navi::make()->build('primary_navigation');
+```
-if ($navigation->isEmpty()) {
- return;
-}
+By default, `build()` uses `primary_navigation` if no menu location is specified.
+
+Retrieving an array of menu items can be done using `all()`:
-return $navigation->toArray();
+```php
+if ($menu->isNotEmpty()) {
+ return $menu->all();
+}
```
-When building the navigation menu, Navi retains the menu object and makes it available using the `get()` method.
+> [!NOTE]
+> Check out the [**examples**](examples) folder to see how to use Navi in your project.
-By default, `get()` returns the raw[`wp_get_nav_menu_object()`](https://codex.wordpress.org/Function_Reference/wp_get_nav_menu_object) allowing you to access it directly.
+### Menu Item Classes
-Optionally, you may pass a `key` and `default` to call a specific object key with a fallback have it be null, empty, or not set.
+By default, Navi removes the default WordPress classes from menu items such as `menu-item` and `current-menu-item` giving you full control over your menu markup while still passing through custom classes.
+
+If you would like these classes to be included on your menu items, you may call `withDefaultClasses()` before building your menu:
```php
-$navigation->get()->name;
-$navigation->get('name', 'My menu title');
+$menu = Navi::make()->withDefaultClasses()->build();
```
-### Acorn Usage
+In some situations, plugins may add their own classes to menu items. If you would like to prevent these classes from being added, you may pass an array of partial strings to `withoutClasses()` match against when building.
-If you are using Navi alongside [Acorn](https://roots.io/acorn/) (e.g. Sage), you may generate a usable view component using Acorn's CLI:
+```php
+$menu = Navi::make()->withoutClasses(['shop-'])->build();
+```
-```sh
-$ acorn make:navi
+### Accessing Menu Object
+
+When building the navigation menu, Navi retains the menu object and makes it available using the `get()` method.
+
+By default, `get()` returns the raw [`wp_get_nav_menu_object()`](https://codex.wordpress.org/Function_Reference/wp_get_nav_menu_object) allowing you to access it directly.
+
+```php
+$menu->get()->name;
```
-Once generated, you may use the [view component](https://laravel.com/docs/11.x/blade#components) in an existing view like so:
+Optionally, you may pass a `key` and `default` to call a specific object key with a fallback when the value is blank:
```php
-
+$menu->get('name', 'My menu title');
```
### Accessing Page Objects
If your menu item is linked to a page object (e.g. not a custom link) β you can retrieve the ID of the page using the `objectId` attribute.
-```php
-# Blade
-{{ get_post_type($item->objectId) }}
+Below is an example of getting the post type of the current menu item:
-# PHP
-objectId); ?>
+```php
+$type = get_post_type($item->objectId)
```
### Accessing Custom Fields
@@ -90,18 +98,34 @@ In a scenario where you need to access a custom field attached directly to your
Below we'll get a label override field attached to our menu [using ACF](https://www.advancedcustomfields.com/resources/adding-fields-menus/) β falling back to the default menu label if the field is empty.
```php
-# Blade
-{{ get_field('custom_nav_label', $item->id) ?: $item->label }}
+$label = get_field('custom_menu_label', $item->id) ?: $item->label;
+```
+
+### Acorn Usage
+
+If you are using Navi alongside [Acorn](https://roots.io/acorn/) (e.g. Sage), you may generate a usable view component using Acorn's CLI:
-# PHP
-id) ?: $item->label; ?>
+```sh
+$ wp acorn navi:make Menu
+```
+
+Once generated, you may use the [view component](https://laravel.com/docs/11.x/blade#components) in an existing view like so:
+
+```php
+
+```
+
+To list all registered locations and their assigned menus, you can use the list command:
+
+```sh
+$ wp acorn navi:list
```
## Example Output
-When calling `build()`, Navi will parse the passed navigation menu and return a fluent container containing your menu items. To return an array of objects, simply call `->toArray()`.
+When calling `build()`, Navi will retrieve the WordPress navigation menu assigned to the passed location and build out an array containing the menu items.
-By default, `build()` calls `primary_navigation` which is the default menu theme location on Sage.
+An example of the menu output can be seen below:
```php
array [
@@ -177,8 +201,6 @@ array [
]
```
-That being said, depending on how deep your menu isβ you can ultimately just keep looping over `->children` indefinitely.
-
## Bug Reports
If you discover a bug in Navi, please [open an issue](https://github.com/Log1x/navi/issues).
diff --git a/composer.json b/composer.json
index 310cd8b..3da0252 100644
--- a/composer.json
+++ b/composer.json
@@ -26,7 +26,8 @@
"php": "^8.0"
},
"require-dev": {
- "laravel/pint": "^1.14"
+ "laravel/pint": "^1.14",
+ "roots/acorn": "^4.3"
},
"extra": {
"acorn": {
diff --git a/examples/vanilla/template-parts/site-nav.php b/examples/vanilla/template-parts/site-nav.php
index 5d14698..bd1e87b 100644
--- a/examples/vanilla/template-parts/site-nav.php
+++ b/examples/vanilla/template-parts/site-nav.php
@@ -11,7 +11,7 @@
isNotEmpty() ) : ?>