title: wordpress get_category_by_slug if true add add class
body: <p>Good afternoon , this is the problem :
  I have an asside menu , this menu has 4 categories and each of this categories has many subcategories , What I am trying to do is that when I am on the page of a subcategory I give a class to a <li> on the left menu , a class of active so the category of the subcategory I am in stays opens .
  Whole code here : <a href="https://pastebin.com/Q09eE9nB" rel="nofollow noreferrer">https://pastebin.com/Q09eE9nB</a></p>
  
  <pre><code>$categories = get_categories( array(
  'orderby' =&gt; 'name',
  'order'   =&gt; 'ASC',
  'parent' =&gt; 52,
  'hide_empty' =&gt; 0
  </code></pre>
  
  <p>));</p>
  
  <pre><code>            &lt;?php if( $categories ): ?&gt;
          &lt;ul class="main-categ"&gt;
              &lt;?php foreach ( $categories as $kCat =&gt; $vCat ): ?&gt;
                  &lt;li class="main-item &lt;?php echo get_category_by_slug( $categories ) == $subCategories ? 'active' : ''; ?&gt;"&gt;&lt;?php
                                  $subCategories = get_categories( array(
                                      'orderby' =&gt; 'name',
                                      'order'   =&gt; 'ASC',
                                      'parent' =&gt; $vCat-&gt;cat_ID,
                                      'hide_empty' =&gt; 0
                                  ));?&gt;
  
                  &lt;a class="main-link" href="#&lt;?php echo $vCat-&gt;slug; ?&gt;" data-cat="&lt;?php echo $vCat-&gt;slug; ?&gt;"&gt;&lt;?php echo $vCat-&gt;name; ?&gt;&lt;/a&gt;
                  &lt;?php if( $subCategories ): ?&gt;
                  &lt;ul class="subcateg"&gt;
                      &lt;?php foreach ( $subCategories as $kSub =&gt; $vSub ): ?&gt;
                      &lt;li&gt;&lt;a href="&lt;?php echo esc_url( get_category_link( $vSub-&gt;cat_ID ) ); ?&gt;"&gt;&lt;i class="fa fa-angle-double-right"&gt;&lt;/i&gt; &lt;?php echo $vSub-&gt;name; ?&gt;&lt;/a&gt;&lt;/li&gt;
                      &lt;?php endforeach; ?&gt;
                  &lt;/ul&gt;
                  &lt;?php endif; ?&gt;
              &lt;/li&gt;
              &lt;?php endforeach; ?&gt;
          &lt;/ul&gt;
  </code></pre>