How to add a post or page tag to the list of classes appearing in the body tag’s class attribute?
You’re close. Your first attempt is using get_the_tags incorrectly. The function accepts the post ID you want to get the tags from. In your example, there is no $tag global, so $tag->name is trying to fetch a property of a non-object. In your second attempt, a single post won’t have any tag-related query vars, that … Read more