Created
July 6, 2017 16:16
-
-
Save netdesignr/3b6f1be4cae6ebc4d166f1f89ee3458f to your computer and use it in GitHub Desktop.
Get Wordpress categories of the post and output each category with no link the attached followed by a comma
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
/** | |
* Get categories of the post | |
* Remove the links | |
* Output each category followed by a comma | |
* Comma is not added on the last item | |
* @param $arr e.g. get_the_category() | |
*/ | |
function get_cat_profile($arr) | |
{ | |
$counter = 0; | |
if (count($arr) != 0) { | |
foreach ($arr as $category) { | |
++$counter; | |
echo count($arr) == $counter ? $category->cat_name . '' : $category->cat_name . ', '; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment