If you want to get Tag ID, when you already have the Tag Name, following code snippet can be used.
$tag = get_term_by ( 'name', single_tag_title( '', false ), 'post_tag' );
$tag_id = $tag->term_id;
If you don’t have the Tag Name already, this code can be used.
$tag_id = get_queried_object()->term_id;
I have tested both codes on Tag Archive pages.
Leave a Reply