Sometimes, browsers just don’t behave. While working on a WordPress site, I had a particular styling issue that was affecting Safari. I was wondering what the best way to target the browser was.

If you didn’t know, there are some primitive browser detection booleans that are built into WordPress.

Using those primitives, I was able to whip up a little snippet that adds classes to the body tag depending on the browser - no plugins required.

As you can see, we simply loop over each one of those browser booleans and append them to the output.

Easy, and no plugin needed. Just add that code to your functions.php file.