Created
April 5, 2019 14:48
-
-
Save imagebox/0ae62f681dd6cf2aef90b637acfd99ce to your computer and use it in GitHub Desktop.
[WordPress | Get the First Category] // Get the first category on a single post by slug or name. #WordPress #post #category
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get the first category on a single post by slug or name. | |
$category = get_the_category(); | |
$currentcat = $category[0]->cat_ID; | |
$currentcatname = $category[0]->cat_name; | |
$currentcatslug = $category[0]->slug; | |
echo $currentcatname; | |
echo $currentcatslug; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment