@Dom I’ve spent more time than I care to admit working with WP menus. What exactly are you trying to accomplish and where are you running into issues?
Be aware that a few things are happening when you make a WP menu in Pinegrow. First, Pinegrow uses its Menu Walker to translate your HTML menu to use in WordPress and to add the relevant classes, then you still need to style the classes and add any interactions you want for drop-down, etc.
Bootstrap 4 made it all pretty easy since they had built in support for most of the things WP does, but Tailwind relies on you to build out the logic. I’ve done it in both Pinegrow Interactions and Alpine.js and they both work fine.
I agree though, that this is one of those areas that needs a lot of updates and clarifications in the Pinegrow documentation. Menus are confusing enough when you are building them in HTML, and downright infuriating when you throw a CMS into the mix. “It just works” is definitely not applicable here.
@adamslowe Essentially I’m trying to achieve a result where if I am for example on the home page then The relevant menu item will be red as opposed to say a normal colour of black.
I have the menu picking up the WordPress menu without issue, I am assuming that the classes set on the first li tag are what Pinegrow then uses to determine the styling but of course one should never assume.
The interactions work nicely now, I’d like to get my head firmly wrapped around where Pinegrow is determining the styling from and then lastly I will turn to accessibility which I anticipate will cause problems.
I wouldn’t try to mess with trying to style current links with Tailwind. This is one of those places where regular CSS is a bit more appropriate.
Knowing that WP applies a .current_page_item class to the li element for the active page, you can just write a simple rule like the one below.
.current_page_item a {
color: red;
}
Also, I’m pretty sure WP still doesn’t add the aria-current="page" attribute by default, and I doubt Pinegrow does it for us either. I have the following snippet in my custom.php to handle that for me.
/**
* Adds aria-current-"page" to the menu item for the current page
*/
function add_attribute_to_current_menu_item( $atts, $item, $args ) {
// check if this item represents the current post
if ( $item->object_id == get_the_ID() )
{
// add the desired attributes:
$atts['aria-current'] = 'page';
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'add_attribute_to_current_menu_item', 10, 3 );
/**
* Adds aria-current-"page" to the menu item for the current page
*/
function add_attribute_to_current_menu_item( $atts, $item, $args ) {
// check if this item represents the current post
if ( $item->object_id == get_the_ID() )
{
// add the desired attributes:
$atts['aria-current'] = 'page';
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'add_attribute_to_current_menu_item', 10, 3 );
@adamslowe Thanks for that. aria-current attribute now working nicely. Not having as much success with the active menu item styling but it will be a stupid error on my part. I don’t doubt that your suggestion works.