Is there a php or javascript code that can detect the current user’s page and then add <a class="active"> to an item in a ul (my menu). I include my menu in my pages with PHP include so making change is easy; I only have to edit it once. But, with that method, I can’t individually set each page to have a class="active". How can I do this?
Is there a php or javascript code that can detect the current user’s page
Share
If I’m understanding your question correctly, what I usually do is set a variable before I include the header, like
And then in the header I’d have an if statement in each link
Could be ways to improve it, but it’s simple if your menu isn’t too big.