wordpress snippets last updated   : October 6, 2014
we now have 641 snippets

Add body_class to page templates in wordpress

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will let you add a body_class based on a specific page template.

read more

Setup whitelist body_class to remove unwanted classes

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will let you create a white-list of terms to include in body_class. This is a great way to filter out many of the unwanted classes added

read more

Add custom body_class to all post and pages

wordpress snippet

This is similar to another body_class post I made however I had a few emails asking about just adding a specific class to the body on every page. Adding this snippet to the functions.php of your wordpress theme will let you add specific classes to wordpress body_class function. Don’t forget to add <?php body_class(); ?> to the body tag within header.php.

read more

Add parent page slug to body_class

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will add the parent page slug to the body_class. Displayed like this <body class=”parent-PAGESLUG”> this can be a great way if you need to style elements on specific pages.

read more

Browser detection and OS detection with body_class

wordpress snippet

Add the first snippet to the functions.php of your wordpress theme then add the second snippet within the body tag of your wordpress header.php template.
<body <? body_class(); ?>>
This snippet will add class based on the users operating system “windows, mac, linux” and also the browser including iphone and if Internet explorer the specific version.

read more