How to highlight current page link in navigation using PHP

Have you found a better code to highlight the current page link of a web page? We know that navigation is one of the most important parts of a website. This may serve as a breadcrumb for users to inform them their current location on the site. One way to do this is to highlight the current page link in the navigation.

In plain HTML sites, this task isn’t easy. If you have 1,000 pages in your website, you have to add a CSS class in all the pages. However, by using php-includes under a PHP server, you can include a file on every page and make the changes on a single file by adding a class to li tag.

Below is an example of a page that uses php includes.

The “header.php” is located on “includes” folder same as the “footer.php”. In this manner you only have to modify a single file to make a change to all pages on the site. The code below can be an example on what’s inside the “header.php”.

I found two different PHP codes on the internet to highlight the current page link on the menu, but none of them works. The good thing is I managed to combine both and make it work. Please leave a comment below if you have a better one and let me highlight it.