I'm trying to style the active link with is_page()
function. And it works for the first nav item. But when I click the "om" link it will get styling, but the styling for "hem" remains. But when I click the "blogg" and "tutorial" links none of the links gets any styling.
This is the code that I have in header.php.
<nav>
<button class="menuButton">Meny</button>
<div class="menu">
<a href="#" class="closebtn">x</a>
<ul>
<h2>Meny</h2>
<li class="<?php if (is_page("")) { echo "active-page"; } ?>"><a href="<?php echo site_url(''); ?>">Hem</a></li>
<li class="<?php if (is_page("/om")) { echo "active-page"; } ?>"><a href="<?php echo site_url('/om'); ?>">Om</a></li>
<li class="<?php if (is_page("/blogg")) { echo "active-page"; } ?>"><a href="<?php echo site_url('/blogg'); ?>">Blogg arkiv</a></li>
<li class="<?php if (is_page("/tutorial")) { echo "active-page"; } ?>"><a href="<?php echo site_url('/tutorials'); ?>">Tutorials arkiv</a></li>
</ul>
</div>
</nav>
Is this the wrong way to use the is_page()
function? I'm a little lost here. The styling that gets applied is just a simple text-decoration: underline;
CSS style.