function link_words( $text ) {
$replace="";
$tags = get_the_tags();
$count=0;
if ( $tags ) {
foreach ( $tags as $tag ) {
$count++;
echo $sep . '<a href="'.get_tag_link($tag->term_id).'">'.$tag->name.'</a>';
$sep = ', ';
if( $count > 2 ) break;
}
}
}
add_filter( ‘the_content’, ‘link_words’, 10, 1 );
Check this.