title: Add a class to a menu item in WordPress
body: <p>I am creating a theme in WordPress. I want to add a class to a <code>&lt;li&gt;</code> element if the user is on that page.</p>
  
  <p>I have managed to create a dynamic navigation, using following code in my <code>header.php</code>:</p>
  
  <pre><code>&lt;div class="nav"&gt;
      &lt;?php wp_nav_menu( array( 'theme_location' =&gt; 'nav-menu' ) ); ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Which in HTML, translates to:</p>
  
  <pre><code>&lt;div class="nav"&gt;
     &lt;ul&gt;
        &lt;li&gt; Home &lt;/li&gt;
        &lt;li&gt; Products &lt;/li&gt;
        &lt;li&gt; About &lt;/li&gt;
     &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I am hoping to dynamically alter this. If the user is on www.website.com/about, the navigation will change to:</p>
  
  <pre><code>   &lt;div class="nav"&gt;
         &lt;ul&gt;
            &lt;li&gt; Home &lt;/li&gt;
            &lt;li&gt; Products &lt;/li&gt;
            &lt;li class="underline"&gt; About &lt;/li&gt;
         &lt;/ul&gt;
      &lt;/div&gt;
  </code></pre>