I'm using php to highlight my current page.
Everything works correctly however when I first go to the page there is nothing after "/" in the domain name.
Ex: mydomain.com/
How can I highlight that page. It only gets highlighted when I have /index.php
Ex: mydomain.com/index.php
Here's my html:
<nav>
<ul class="cd-primary-nav">
<li><a href="index.php" <?=echoSelectedClassIfRequestMatches("index")?>>Home</a></li>
<li><a href="about.php" <?=echoSelectedClassIfRequestMatches("about")?>>About</a></li>
<li><a href="services.php" <?=echoSelectedClassIfRequestMatches("services")?>>Services</a></li>
<li><a href="brands.php" <?=echoSelectedClassIfRequestMatches("brands")?>>Brands</a></li>
<li><a href="testimonials.php" <?=echoSelectedClassIfRequestMatches("testimonials")?>>Reviews</a></li>
<li><a href="contact.php" <?=echoSelectedClassIfRequestMatches("contact" , "thankyou")?>>Contact</a></li>
</ul>
</nav>
Here's the PHP:
<?php
function echoSelectedClassIfRequestMatches($requestUri)
{
$current_file_name = basename($_SERVER['REQUEST_URI'], ".php");
if ($current_file_name == $requestUri)
echo 'class="selected"';
}
?>
Thanks in advance.