how to get category from url in wordpress

0.69K views
no comments
23 Dec 2016 2:19 am

I was development a section a in my #wordpress theme I need the current category from url, here is I figure out how to get category from url.

$page_position = strpos($_SERVER['REQUEST_URI'],'page');
if($page_position!==false){
    $CAT_URL = substr($_SERVER['REQUEST_URI'],0,$page_position);
} else {
    $CAT_URL = $_SERVER['REQUEST_URI'];
}
$urlslugArray = array_filter(explode('/',$CAT_URL));

$get_the_category = get_category_by_slug(end($urlslugArray));
if($get_the_category){
    $tagtut_title = $get_the_category->name;
    $tagtut_desc = $get_the_category->category_description;
    $posts_found = $get_the_category->count;
}

NOTE:Your Email Address will be not shown and please do not add spamming comments because here is REL="NOFOLLOW" on your links and comments also moderated shown.
<code>Put html css or any language code under this tag</code>