Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save netdesignr/3b6f1be4cae6ebc4d166f1f89ee3458f to your computer and use it in GitHub Desktop.
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
/**
* 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