Sometime we need to fetch only the first tag of a post. We can add one or more tags in a wordpress post as per our requirement. Now in some cases when we are working on single.php file and we need to fetch the first tag among so many tags in all posts.

Just add the below mentioned code in your while loop in single.php file :

$all_tags = get_the_tags();
                $i=0;
                if ($all_tags) {
                    foreach($all_tags as $tags) {
                        $i++;
                        if (1 == $i) {
                            $required_firsttag = $tags->name;
                        }
                    }
                }

 
Now we can use $required_firsttag variable to show first tag of current post.