title: How to add active class to menu item
body: <p>I have my menu in an include file called menu.php and I want to assign a class called 'active' to the <code>&lt;li&gt;</code> to the page that I am on. How can I do this in PHP or JavaScript?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!-- navigation --&gt;
  &lt;nav class="navbar navbar-default" role="navigation"&gt;
  &lt;div class="navbar-header"&gt;
  &lt;button type="button" class="navbar-toggle" data-toggle="collapse" 
          data-target="#collapse"&gt;
  &lt;span class="sr-only"&gt;Toggle navigation&lt;/span&gt;
  &lt;span class="icon-bar"&gt;&lt;/span&gt;
  &lt;span class="icon-bar"&gt;&lt;/span&gt;
  &lt;span class="icon-bar"&gt;&lt;/span&gt;
  &lt;/button&gt;
  &lt;/div&gt;
  &lt;div class="collapse navbar-collapse" id="collapse"&gt;
  &lt;ul class="nav navbar-nav navbar-right"&gt;
    &lt;li&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" 
           aria-haspopup="true" aria-expanded="false"&gt;Insect Control 
        &lt;span class="caret"&gt;&lt;/span&gt;&lt;/a&gt;
      &lt;ul class="dropdown-menu"&gt;
        &lt;li&gt;&lt;a href="insect-control.php"&gt;Insect Control&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="ant-cockroach-control.php"&gt;Ant &amp; Cockroach Control&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="bed-bug-treatment.php"&gt;Bed Bug Treatments&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="fly-control.php"&gt;Fly Control&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="wasp-hornets-bee-control.php"&gt;Wasp, Hornet &amp; Bee Control&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" 
           aria-haspopup="true" aria-expanded="false"&gt;Rodent &amp; Vermin 
        &lt;span class="caret"&gt;&lt;/span&gt;&lt;/a&gt;
      &lt;ul class="dropdown-menu"&gt;
        &lt;li&gt;&lt;a href="rodent-vermin.php"&gt;Rodent &amp; Vermin&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="rats-mice-infestation.php"&gt;Rats &amp; Mice Infestation&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="squirrel-control.php"&gt;Squirrel Control&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;li&gt;&lt;a href="#"&gt;Contact&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  &lt;/nav&gt;
  &lt;!-- end navigation --&gt;</code></pre>
  </div>
  </div>
  </p>