Last active
January 27, 2019 19:47
-
-
Save mdjwel/8f8fa9e99b3bb44167b84665ba230927 to your computer and use it in GitHub Desktop.
Get the first category name and link in WordPress post's while loop.
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 | |
// Get the 1ast category link | |
function Chaoz_first_category_link() { | |
$cats = get_the_terms(get_the_ID(), 'category'); | |
$cat = is_array($cats) ? get_category_link($cats[0]->term_id) : ''; | |
echo esc_url($cat); | |
} | |
// Get the first category link | |
function Chaoz_first_category_link() { | |
$cats = get_the_terms(get_the_ID(), 'category'); | |
$cat = is_array($cats) ? get_category_link($cats[0]->term_id) : ''; | |
echo esc_url($cat); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment