This members-only tutorial provides the code for registering a custom condition using which elements can be output depending on whether the current page's body has the given class or not.
Both == and != operators shall be set so that it is possible to check if the page either has or not has the entered class.
Let's say you want to show a section only on all single posts but not the rest of the pages on your site.
Inspect any single post with your browser DevTools and look for the body tag. It could be something like this:
<body class="post-template-default single single-post postid-299 single-format-standard wp-embed-responsive theme-oxygen-is-not-a-theme oxygen-body woocommerce-js oxygen-aos-enabled" data-aos-easing="ease" data-aos-duration="400" data-aos-delay="0">
The single-post class is unique to all single posts in WordPress.
So you could enter it for the class name in your condition for the Section and it will be output only on all single posts.
Similarly WordPress provides useful classes for different views. You can find the list here.
Install and activate Code Snippets plugin.
Go to Snippets > Add New.
Title: Body Class
This is a premium members-only content.
To view the rest of the content, please sign up for membership ($37/month or $399 one-time).
Already a member? Log in below or here.
Enter your email address to subscribe to this blog and receive notifications of new tutorials by email.
Join 325 other subscribers
Please log in again.
The login page will open in a new tab. After logging in you can close it and return to this page.