title: Get current active category from multi category page
body: <p>I'm here with a little challenge.</p>
  <h2>The context:</h2>
  <p>I am working for a company where I am building a new website for them.
  It is being built in Wordpress, btw everthing is going ok.</p>
  <p>The website has a news and blog page with posts on there.
  BUT a in some special cases a news post can also be part of the blog page.</p>
  <p>So when that happens we set the 2 categories and put the primary at on of the categories.</p>
  <h2>The challenge:</h2>
  <p>When I visit a post with multiple categories I can either go to:</p>
  <pre><code>http://example.com/blog/news_post
  </code></pre>
  <p>or</p>
  <pre><code>http://example.com/news/news_post
  </code></pre>
  <p>But there are some values on the page that are depended on the name of the category. (I know that is usually not a good idea but I have no other choice in this matter).</p>
  <p>When I visit a page I want to get the category that is used to get the field values I need.</p>
  <p>So, when going to the news page I would like to get &quot;news&quot; as category name when use a function to get the name.</p>
  <p>I have tried multiple things the internet said could do the trick but they either don't work or (what happens most) aren't meant for multi category posts but for getting all the cat of the page.</p>
  <p>If you need any more info please let me know.</p>
  <p>PS. I would rather not us the url but if that is the best option I will take it.
  Hope you guys can help</p>
  <h1>EDIT</h1>
  <p>I just managed to do it.
  Although in the end I still used the url it beats the other options with lots of coding.</p>
  <p>I came to this solution after this post by <a href="https://wordpress.stackexchange.com/questions/83999/get-the-current-page-url-including-pagination">René Schubert</a></p>
  <p>I was just out of options when I saw someone there with an answer I tried it and it worked after a little tweak.</p>
  <p>This is the code I have now.</p>
  <pre><code>$url = add_query_arg( $wp-&gt;query_string, '', home_url( $wp-&gt;request ) );
  $category = substr($url, strpos($url, &quot;category_name=&quot;) + 14);
  </code></pre>
  <p>If you have a better way than please let me know :)
  I'm all for better ways.</p>