Get current category ID


function getCurrentCatID(){

global $wp_query;

if(is_category() || is_single()){

$cat_ID = get_query_var('cat');

return $cat_ID;


echo getCurrentCatID();



You must be logged in to post a comment.

  1. Indeed. This is an ancient snippet, maybe I had a reason in the context of my use when I created it. No tellin.

  2. Have been looking for this all over, thanks!

    What is the "or is_single()" supposed to do? Wouldn't the var 'cat' always be empty if is_single??

  3. WordPress is pretty secure. If you have good passwords I wouldn't worry to much. If you google wordpress security plugins you might find some. There are a few that help protect the login system. Login Lockdown if I remember is one.

    I have personally never been hacked, the security at the hosting level is important. Network Solutions got hacked once on a company site that I used to work for.

  4. Good day! Do you know if they make any plugins to safeguard against hackers? I'm kinda paranoid about losing everything I've worked hard on. Any recommendations? eddddkcegebb

  5. You ROCK !!!

  6. thanks for snippet. very helped me.

  7. Thanks, great work...

  8. Hey! That's spot on Adam, exactly what I need. Suprised it isn't already part of the WP core tbh. Cheers

  9. hey, very useful, thanks!