0

OK , I have a Custom Theme generated by Bootstrap. Currently I just added a Navbar (navigation to the theme and I am having trouble on setting ACTIVE navbar in each active page.(by adding active class to the li) For example if I am in Contact us page how I can force the navbar to make the contact us nav active! I alreadt tried

<li <?php is_page( 'Home' ){echo 'class="active"'}> Home</li>
<li <?php is_page( 'About us' ){echo 'class="active"'}> About us</li>

can you please let me know how I can do this?

1
  • Please edit your question to make clear and understandable what you're asking, additionally read How to Ask. – Nicolai Nov 18 '13 at 12:29
1

Looks like its just your PHP formatting, you have the right idea! try this:

<pre class="prettyprint"><code class="language-php">
<?php 

if (is_page( 'Home' ) {
    $class="active";
}
elseif (is_page( 'About' ) {
    $class="active";
}
else {
    $class="";
}

?>

<li class="<?php echo $class; ?>"Home</li>
<li class="<?php echo $class; ?>"About</li>
</code></pre>
3
  • Can you please add more explanation to your answer? – Maruti Mohanty Nov 18 '13 at 16:57
  • Hi Frank I like your idea and look logical to me but it is not working! I mean there must be syntax error since I am getting white blank page from WordPress! – Mona Coder Nov 18 '13 at 19:05
  • Does anyone have any Idea about this? Please? – Mona Coder Nov 19 '13 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.