Test if post has a category

I need to display some HTML only if the post being displayed has a category – not a specific category, just any category at all.

I tried if (!is_empty(get_the_category($post->ID))), but for some reason this isn’t working. Has anone else had the same issue?

Related posts

Leave a Reply

1 comment

  1. Use has_category instead.

    if (has_category('',$post->ID)) ...

    If you want to use it in The Loop, you don’t need to specify the ID.

    if (has_category()) ...