title: How to add multiple categories in function WordPress
body: <p>Wordpress - functions.php</p>
  <p>I'm using this function to automatically add custom structure in url for posts in a specific categorie.</p>
  <p>But now I would like to know how I could add multiple categories without having to copy this function over and over.</p>
  <p>Other solution could be to have this function work for the parent post category and all child categories.</p>
  <pre><code>// url structure
  
  add_filter( 'post_link', 'custom_permalink', 10, 3 );
  function custom_permalink( $permalink, $post, $leavename ) {
      // Get the category for the post
      $category = get_the_category($post-&gt;ID);
      if (  !empty($category) &amp;&amp; $category[0]-&gt;cat_name == &quot;b&quot; ) {
          $cat_name = strtolower($category[0]-&gt;cat_name);
          $permalink = trailingslashit( home_url('/questions/' . $post-&gt;post_name .'/' ) );
      }
      return $permalink;
  }
  
  add_action( 'init', 'custom_rewrite_rules' );
  function custom_rewrite_rules() {
      add_rewrite_rule(
          'b/([^/]+)(?:/([0-9]+))?/?$',
          'index.php?category_name=b&amp;name=$matches[1]&amp;page=$matches[2]',
          'top' // The rule position; either 'top' or 'bottom' (default).
      );
  }
  </code></pre>