Skip to content

Instantly share code, notes, and snippets.



Created Jun 9, 2015
What would you like to do?
WordPress: If the post has several categories, display the first one only.
$category = get_the_category( get_the_ID() );
if ( $category ) :
<span class="entry-category">
<a href="<?php echo esc_url( get_category_link( $category[0]->term_id ) ); ?>"><?php echo esc_attr( $category[0]->name ); ?></a>
<?php endif; // End if category ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment