WordPress plugin intelligence profile

WP247 Body Classes

Add unique classes to the body tag for easy styling based on various attributes (archive, user, post, mobile, scrolling) and WordPress "is" …

WP PlugIndex snapshot

Current directory snapshot

Tested up to WordPress 6.5
Current version2.2.0
WordPress coverageTested up to WordPress 6.5
Minimum stackWP 4.0 · PHP —
Directory statusactive
Last directory update24 May 20242y ago
Active installations200Adoption metric — not a quality score
WordPress.org rating4.5 / 5 from 6 ratings
Official packageDirect from WordPress.org

Repository metrics are context, not quality scores. Active installations measure adoption and can strongly reflect a plugin’s age and historical popularity. Ratings, recent updates and “Tested up to” metadata also do not guarantee modern code, error-free operation, security, feature completeness or suitability for a particular site. Why active installs don’t tell the whole story →

WP PlugIndex currently records WP247 Body Classes version 2.2.0 as active, updated 2y ago and tested up to WordPress 6.5.

Overview

About this plugin

Add unique classes to the body tag for easy styling based on post attributes (post type, slug, and ID) and various WordPress “is” functions:

  • wp_is_mobile()
  • is_home()
  • is_front_page()
  • is_blog()
  • is_admin()
  • is_admin_bar_showing()
  • is_404()
  • is_super_admin()
  • is_user_logged_in()
  • is_search()
  • is_archive()
  • is_author()
  • is_category()
  • is_tag()
  • is_tax()
  • is_date()
  • is_year()
  • is_month()
  • is_day()
  • is_time()
  • is_single()
  • is_sticky()
  • $post->post_type
  • $post->name
  • $post->ID
  • wp_get_post_categories() (Page/Post Categories)
  • wp_get_post_tags() (Page/Post Tags)
  • $user->nicename
  • $user->id
  • $user->roles
  • $user->allcaps
  • $archive->slug (e.g. Category slug, Tag slug, etc.)
  • $archive->id (e.g. Category id, Tag id, etc.)

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:

  • is-scroll-top (at the top of the page – synonym for is-not-scroll)
  • is-not-scroll-top (not at the top of the page – synonym for is-scroll)
  • is-scroll (not at the top of the page – synonym for is-not-scroll-top)
  • is-not-scroll (at the top of the page – synonym for is-scroll-top)
  • is-scroll-top-px (has not reached the scroll start value for scroll measurement by pixels)
  • is-scroll-top-vh (has not reached the scroll start value for scroll measurement by viewport height)
  • is-scroll-top-dh (has not reached the scroll start value for scroll measurement by document height)
  • is-scroll-10-px (scrolled down 10 pixels)
  • is-scroll-8-vh (scrolled down 8% of the viewport height)
  • is-scroll-5-dh (scrolled down 5% of the document height)
  • is-scroll-mid-px (has reached the scroll start value but not the scroll limit for scroll measurement by pixels)
  • is-scroll-mid-vh (has reached the scroll start value but not the scroll limit for scroll measurement by viewport height)
  • is-scroll-mid-vh (has reached the scroll start value but not the scroll limit for scroll measurement by document height)
  • is-scroll-max-px (has reached the scroll limit for scroll measurement by pixels)
  • is-scroll-max-vh (has reached the scroll limit for scroll measurement by percent of viewport height)
  • is-scroll-max-dh (has reached the scroll limit for scroll measurement by percent of document height)

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:

  • is-mobile
  • is-tablet
  • is-phone
  • Mobile Operating System
  • Mobile Browser
  • Type of tablet
  • Type of phone

This plugin adds classes to the html body tag indicating:

-

is-not-mobile)

-

is-? where? is the post type (page, post, whetever special post types are defined) ).

is-post

-

-! where? is the post type and!

is the post slug).

g. is-post-hello-world

-

-# where? is the post type and # is the post ID).

g. is-page-1

-

is-not-archive)

If the page being displayed is an archive

-

is-? where? represents the type of archive (author, category, date, tag) )

is-author

-

-! where? is the archive type and!

is the archive slug)

g. is-category-uncategorized

-

-# where? is the archive type and # is the archive ID)

g. 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.

Custom Body Classes

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';

user-can-manage-options qualifier in our CSS styling.

Example

Suppose you have a large h1 top margin that you want to eliminate on mobile devices to avoid a lot of white space. is-mobile class is desired, all you need to do is add this line to your CSS:

is-mobile h1 {

margin-top: 0;

}

Suppose you have a sticky header but want to shrink it by dynamically reducing the top and bottom padding from 25px to 5px as the viewer scrolls down the page based on 20 pixel scroll increments up to 80 pixels of scrolling:

Set WP247 Body Classes Scroll setting to “Scroll by Pixel” with a 10 pixel increment and an 80 pixel limit and then add the following to your CSS:

is-scroll-20-px header {

padding-top: 20px;

padding-bottom: 20px;

}

is-scroll-40-px header {

padding-top: 15px;

padding-bottom: 15px;

}

is-scroll-60-px header {

padding-top: 10px;

padding-bottom: 10px;

}

is-scroll-max-px header {

padding-top: 5px;

padding-bottom: 5px;

}

WordPress.org metadata

Plugin tags

Topics listed for this plugin in the WordPress.org directory.

  • post type
  • user capabilities
  • user roles
  • mobile
  • scroll
Compatibility & maintenance

Compatibility & maintenance

Tested up to WordPress 6.5

Not yet marked as tested with WordPress 7.1. WordPress.org currently lists Tested up to 6.5.

Current WordPress releaseWordPress 7.1
WordPress.org Tested up to6.5
Minimum requirementsWordPress 4.0 · PHP not listed
Update activity24 May 20242y ago

“Tested up to” is directory metadata supplied by the plugin author. WP PlugIndex does not turn an older declaration into a claim that the plugin is incompatible.

Changes recorded by WP PlugIndex

Recent tracked changes

No tracked version or compatibility changes have been recorded by WP PlugIndex yet.

Tracking & source

WP PlugIndex tracks public WordPress.org directory metadata and records selected version, compatibility and availability changes as they are detected.

Plugin watchlist

Watch this plugin

Sign in to your WP PlugIndex account or create a free account. Free accounts can watch up to 5 plugins and see what changed.

Watch limit

Watchlist limit reached

You have reached your current active watch limit.