Categories and Tags returning 404 on the sidebar when using ugly permalinks

Instead of:

home_url() . "/tag/" . $i->slug

Use get_term_link() function. It will return the link for the term according with the current configuration:

// Assuming $i is a term object
get_term_link( $i->term_id )

For example, your printTags() function would be:

function printTags($tags){
    //Check to see if tags are provided
    if ($tags!=false) {
      $return = '';
      foreach ($tags as $i){
        $return .= '<li><a href="' . get_term_link( $i->term_id ) . '">' . $i->name . '</a></li>';
      }
      return $return;
    }
}

Leave a Comment