Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scottnunemacher/49e039d96473444ef9ab0be91ae178fa to your computer and use it in GitHub Desktop.
Save scottnunemacher/49e039d96473444ef9ab0be91ae178fa to your computer and use it in GitHub Desktop.
Wordpress - Display Loop's Post Category Link - Ex: display category link for an article
<?php
//Note Wordpress only uses the first category applied to a post.
$category = get_the_category();
if (!empty($category)) {
echo 'Category: <a class="post-category" href="' . esc_url(get_category_link($category[0]->term_id)) . '">' . esc_html($category[0]->name) . '</a>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment