Add custom classes to the <body>
with WPMasterToolKit
Adding custom CSS classes to the tag <body>
of a page can be an essential feature for WordPress developers and site owners who wish to adjust the design or enable specific functionality for particular pages or types of content. With this in mind, we've developed the Custom Body Class within our WPMasterToolKit plugin.
This module makes it easy to add custom CSS classes to the <body>
individual pages, offering even greater flexibility in terms of personalization.
Which plugin can this module replace?
The module Custom Body Class from WPMasterToolKit can replace several plugins that specialize in managing CSS classes on the <body>
such as :
- Insert Body Class Plugin for WordPress or similar plug-ins that add a simple interface for customizing
<body>
. - Tailor-made solutions developed by themes or agencies for this specific functionality.
With this module, you won't need to search for or use an additional plugin: WPMasterToolKit manages everything in a single solution.
Main features of the module
This is what the module offers Custom Body Class :
- Adding custom classes to specific pages : Thanks to a metabox added to the content editor, administrators or editors can define CSS classes to be applied to the
<body>
of a page or article. - Selective activation by content type : The administrator can choose the content types (articles, pages, custom post types, etc.) for which this feature will be activated.
- Dynamic customization : Defined classes are applied dynamically when pages are loaded onto the site, offering flexibility without modifying the source code.
- Ease of management in the administration interface : A configuration sub-page allows global control of parameters.
How to use the Custom Body Class module
- Activate module : If the module is not activated in WPMasterToolKit, go to the modules page and activate it.
- Configuring content types :
- Go to the module parameters section, available via a sub-menu in WPMasterToolKit > Custom Body Class.
- Select the content types (pages, articles, or custom types) for which you wish to activate the metabox.
- Go to the module parameters section, available via a sub-menu in WPMasterToolKit > Custom Body Class.
- Select the content types (pages, articles, or custom types) for which you wish to activate the metabox.
- Adding classes to content :
- When editing an article or page, a metabox entitled WPMasterToolKit (Custom Body Class) will be available in the side column.
- Enter the CSS classes you wish to add to the field, separating them with commas (e.g. :
class1,class2,my-custom-class
).
- Save changes : Once the classes have been added, click on "Update" or "Publish". The classes will be added automatically to the
<body>
when the page is viewed.
Why did we make these technical choices?
Optimum performance thanks to conditional activation
With WPMasterToolKit, each module is loaded only when it is activated. This reduces the memory footprint and optimizes performance. The module Custom Body Class injects its functionalities only if you have activated and configured it beforehand.
Filtering based on content type
We have integrated granular control to allow administrators to limit this functionality to the content types required. This avoids unnecessarily adding meta-boxes in the administration interface, or modifying content where the functionality is not relevant.
Native integration with WordPress
The module uses the WordPress filter body_class
This ensures seamless integration with the WordPress core, themes and other plugins that may modify the <body>
.
Conclusion
The module Custom Body Class from WPMasterToolKit is a simple yet powerful solution for WordPress administrators and developers looking to customize their pages with dynamic CSS classes. It combines the flexibility of easy class management within the administration with the optimized performance of a well-designed plugin.
If you're tired of using multiple plugins to manage small features, WPMasterToolKit simplifies your life by combining everything into one. Activate this module today and discover how it can transform your style and feature management.