Support » Plugins and Hacks » Link current tags of an post in content

  • Hi, I try to link all set tags of an post if they are called in the text of this article and show an tooltip if it has tag description.

    Example: the Post is tagged with “wonderful” and the text is “What an wonderful world.”

    Here is the code I made so far, but it doesn’t work … :/

    <?php
    //show linked tags with description tooltip in post content
    function wpfst_show_tags($text){
    	if( is_single() ) {
    		$tags = get_the_tags( array( 'hide_empty' => false ) );
    		if ($tags) {
    		  $tagged_text = $text;
    		  foreach ($tags as $tag) {
    		  	$tagged_text = wpfst_add_tag_link_to_content($tagged_text, $tag->name, get_tag_link( $tag->term_id ), $tag->description);
    		  }
    		  return $tagged_text;
    		  print $tags;
    		}
    	}
    }
    add_filter('the_content', 'wpfst_show_tags');
    add_filter('the_excerpt', 'wpfst_show_tags');
    
    function wpfst_add_tag_link_to_content($tagged_text, $tagname, $taglink, $tagdescription){
        $replace = array(
        	$tagname => ($tagdescription? '<a style="position: relative;" href="'.$taglink.'" title="All posts about ' .$tagname . '" data-tooltip="' . $tagdescription . '">'.$tagname . '</a>':'<a style="position: relative;" href="'.$taglink.'" title="All posts about ' .$tagname . '">' . $tagname . '</a>')
    	);
    	$tagged_text = str_replace(array_keys($replace), $replace, $tagged_text);
    	return $tagged_text;
    }
    ?>

    Does anyone has an idea? Thanks

  • The topic ‘Link current tags of an post in content’ is closed to new replies.