I've the following code which gives the list of the portfolio category as text. What can I do to have them as links instead? thank you
function thb_display_category_cus() {
if ('portfolio' === get_post_type() ) {
$categories = get_the_term_list( get_the_ID(), 'portfolio-category', '', ', ', '' );
if ($categories !== '' && !empty($categories) ) {
$categories = strip_tags($categories);
}
echo
esc_html($categories);
} else {
the_category(', ' );
}
}
I've the following code which gives the list of the portfolio category as text. What can I do to have them as links instead? thank you
function thb_display_category_cus() {
if ('portfolio' === get_post_type() ) {
$categories = get_the_term_list( get_the_ID(), 'portfolio-category', '', ', ', '' );
if ($categories !== '' && !empty($categories) ) {
$categories = strip_tags($categories);
}
echo
esc_html($categories);
} else {
the_category(', ' );
}
}
Share
Improve this question
asked Sep 30, 2019 at 21:55
DandeDande
351 silver badge8 bronze badges
2
|
1 Answer
Reset to default 1WebElain was correct but, you've also got the HTML escaped. The entire chunk of code should be:
function thb_display_category_cus() {
if ('portfolio' === get_post_type() ) {
$categories = get_the_term_list( get_the_ID(), 'portfolio-category', '', ', ', '' );
echo $categories
} else {
the_category(', ' );
}
}
strip_tags()
function is removing the links. – WebElaine Commented Sep 30, 2019 at 22:00<a href="https://yoursite/portfolio-category/test/" rel="tag">test</a>
(as pure text). How can I transform this in a hyperlink? – Dande Commented Sep 30, 2019 at 22:41