The growing library of 300+ ready-to-use templates that work with all WordPress themes including Astra, Hello,...
Add unique classes to the body tag for easy styling based on various attributes (archive, user, post, mobile, scrolling) and WordPress "is" …
WP247 Body Classes is a WordPress plugin that allows you to add unique classes to the body tag based on various post attributes and WordPress functions. This can help with styling individual posts or groups of posts by using specific class names. The plugin also includes functionality to detect user scrolling and mobile device types, adding relevant classes to the body tag accordingly.
This plugin is suitable for developers or site owners who want to enhance the styling of their WordPress site by applying custom classes based on post characteristics and user interactions. It provides a flexible way to manage CSS styling through body classes, which can be particularly useful for theme development or custom layouts.
Best for: This plugin suits WordPress developers and site owners looking to customise their site's styling based on post attributes and user interactions.
What it does well
Where it falls short
WP247 Body Classes offers a straightforward solution for adding custom body classes in WordPress, but users should have some CSS knowledge to fully leverage its capabilities.
wescleveland's own description of WP247 Body Classes, lightly tidied.
Add unique classes to the body tag for easy styling based on post attributes (post type, slug, and ID) and various WordPress “is” functions:
Add post specific classes to the body tag in the post editor. Use any class name you want to uniquely style an individual post or a set of posts.
Add classes based on user scrolling through the page. You can check things like:
Add classes based on the results from mobiledetect.net’s Mobile_Detect script. This script parses the value passed by the browser in the HTTP_USER_AGENT string. Consequently, mobile detection is more of an art than a science and, unfortunately, is not perfect. You can check things like:
This plugin adds classes to the html body tag indicating:
whether or not the requesting device is a mobile device (.is-mobile or .is-not-mobile)
the type of post being viewed (.is-? where ? is the post type (page, post, whetever special post types are defined) ).
E.g. .is-page or .is-post
the slug of the post being viewed (.is-?-! where ? is the post type and ! is the post slug).
E.g. a post with slug “hello-world’ would have class .is-post-hello-world
the ID of the post being viewed (.is-?-# where ? is the post type and # is the post ID).
E.g. a post with ID “1” would have class .is-page-1
whether or not the requested page shows archived results (.is-archive or .is-not-archive)
If the page being displayed is an archive
the type of archive being viewed (.is-? where ? represents the type of archive (author, category, date, tag) )
E.g. .is-author
the slug of the archive being viewed (.is-?-! where ? is the archive type and ! is the archive slug)
E.g. a category with slug “uncategorized’ would have class .is-category-uncategorized
the ID of the archive being viewed (.is-?-# where ? is the archive type and # is the archive ID)
E.g. a category with ID “1” would have class .is-category-1
How far down the page the viewer has scrolled in pixels or as a percentage of viewport height or as a percentage of document height
Post specific class(es) that are set in the post editor
Use these classes in your styling to provide a better browsing experience for your viewers.
Create your own Custom Body Classes by adding your PHP code in the “Custom Body Classes” section.
Here’s an example. Not sure why we would want to do it, but suppose we want to do some custom styling when the page is being displayed to someone that can manage WordPress options. We might enter something like:
if (current_user_can('manage_options')) $classes[] = 'user-can-manage-options';
Other plugins for libraries and archives.
The growing library of 300+ ready-to-use templates that work with all WordPress themes including Astra, Hello,...
Securely upload SVG files to your media library, with built-in sanitization and advanced features for styling...
Easily replace any attached image/file by simply uploading a new file in the Media Library edit view - a real...
HappyAddons packs Header Footer Builder, Megamenu, Single Post, Archive Page, & 500+ Ready Templates into...
CMB2 is a metabox, custom fields, and forms library for WordPress that will blow your mind.
The best WordPress templates, pattern, and layout library with 1,000+ designs built for the Gutenberg block ed...