0

I try to add link of tag archive in text that contain tag.

For example:- if i have tag that name "football" and in single.php i display the content like "the_content();", So now when article have word like " football " it must be add link to get me all article have word " football ".

I do this function, but i need the the link of tag archive ???

function tag_content_replace($post_content) {
   global $wp_query, $post;

   if (!is_single() ) return $post_content;
  $content_with_tags_link = $post_content;

 $posttags = get_the_tags();
 if ($posttags) {
   foreach($posttags as $tag) {
   $tag_name = ' '.$tag->name.' ';
  $link_ = ' <a href="'.get_permalink(get_the_ID()).'" title="'.$tag->name.'">'.$tag->name.'</a> ';
  $content_with_tags_link =  str_replace($tag_name , $link_ ,$content_with_tags_link)  ; 

  }
}


$content_with_tags_link = preg_replace('/<img.*src="(.*?)".*\/>/', '<a href="'.get_permalink(get_the_ID()).'" title="'.get_the_title(get_the_ID()).'"><img src="\1" alt="'.get_the_title(get_the_ID()).'" title="'.get_the_title(get_the_ID()).'" /></a>', $content_with_tags_link);


 return  $content_with_tags_link;
}

1 Answer 1

0

The standard way to create the tag-archive page link is to ask it to WordPress with:

echo get_tag_link($tag_id_or_tag_object)

the function is smart enough to deal with id(s) or full tag objects like the ones returned by get_the_tags().

See here for more about the tag link: http://codex.wordpress.org/Function_Reference/get_tag_link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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