Skip to content

Instantly share code, notes, and snippets.

@satrya

satrya/category.php

Created Jun 9, 2015
Embed
What would you like to do?
WordPress: If the post has several categories, display the first one only.
<?php
$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>
</span>
<?php endif; // End if category ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment