Hello Friends, This is very simple thing which I am going to share in this article. I am going to explain you how to get Tag Id by Tag name, I know you might be thinking why I need that but when I was creating one plugin then I needed to get tag names by tag id. So I made a simple function to get tag name by tag id.
So below is function to get tag name by tag id :
function get_tag_ID($tag_name) { $tag = get_term_by('name', $tag_name, 'post_tag'); if ($tag) { return $tag->term_id; } else { return 0; } }
So above code is used to get tag name by tag id, Just simply put this function in your theme functions.php file and then call it anywhere and pass tag name in it, it will return tag id.
I hope it will help someone in WordPress get tag id by tag name.
I am PHP Freelancer, Hire WordPress Developer India and Hire WordPress Programmer. If you have any projects related to WordPress or PHP you can contact me.
5 Comments
Nice function. Thanks.
Thanks, perfect!
Worked like charm.
The title says “Get Tag Id By Tag Name”, and int text you say ” I am going to explain you how to get Tag name by Tag id”
thank you 🙂
thanks 🙂