0

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(', ' );
      }
    }
  • Take out your second "if" statement - the strip_tags() function is removing the links. – WebElaine Sep 30 at 22:00
  • thanks. ok now I've that as result <a href="https://yoursite.com/portfolio-category/test/" rel="tag">test</a> (as pure text). How can I transform this in a hyperlink? – Dande Sep 30 at 22:41
0

WebElain 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(', ' );
      }
    }
  • perfect, thanks! – Dande Sep 30 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.