Tag Info

I don't really understand what you're trying to do in your PHP.
Simplest way (and, in my opinion, the more elegant solution, as this is a presentational issue) would be to do this in CSS. By default, WordPress puts plenty of helpful CSS in your <body> tag, e.g.:
<body class="single single-post postid-53 single-format-standard logged-in ...