Created
August 29, 2023 19:18
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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