WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to get the current category slug? (3 posts)

  1. xfatpanda
    Member
    Posted 5 years ago #

    When I'm in a category page, how can I get the current category slug?
    Thanks in advance.

  2. MichaelH
    Member
    Posted 5 years ago #

    Try:

    <?php
    if (is_category( )) {
      $cat = get_query_var('cat');
      $yourcat = get_category ($cat);
      echo 'the slug is '. $yourcat->slug;
     }
    ?>
  3. xfatpanda
    Member
    Posted 5 years ago #

    Awesome! It works perfect!
    Thank you very much!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags