This might be another easy one, but my limited PHP knowledge isn’t helping me.
I basically need a way to add an “active” class to the currently active link of the main page. I’ tried to follow the Custom Menu code in the docs but my page kept bombing.
My markup looks like this right now, not sure what I need to do to add an “active” class to each link (not using a loop so as to keep the li id’s in place). Am thinking to just check If current page is ‘About’ or whatever, echo “class=“active”” or something:
Yeah, I need to target the li’s individually for a flexbox thing I’m doing with them. However, that is good to know. I may play with that as well, but for now, the first bit of code was exactly what I was looking for.
Hmmmmm, wait, maybe this isn’t quite right. It’s applying the active class on all of my menu links.
OK, I noticed through some other tutorial I had configured a $currentpage variable further down the line (was using it to assign the page name as a class name to a section). That looked like so:
It doesn’t work in his case because he doesn’t use a loop to construct the menu, so that $page is the same for every menu item. In order for the code snippet to work in his case he’d have to adjust it slightly for each menu item, maybe like so: