php-wordpressHow to use body_class() in WordPress with PHP?
The body_class()
function in WordPress is used to add custom classes to the <body>
element of a WordPress page. This can be used to target specific pages or elements with custom CSS.
Example code
<body <?php body_class(); ?>>
Output example
<body class="home page-template page-template-page-templates page-template-full-width page-template-page-templatesfull-width-php page page-id-2 logged-in admin-bar no-customize-support">
Code explanation
body_class()
: This is the function that adds the classes to the<body>
element.<body>
: This is the HTML element that the classes are added to.home
: This is an example of a class that is added to the<body>
element.
Helpful links
More of Php Wordpress
- How to disable PHP warnings in WordPress?
- How to send an email using PHP in WordPress?
- How to use get_header in WordPress using PHP?
- How to configure Nginx for WordPress?
- How to check the PHP version in WordPress?
- How to increase the upload limit in WordPress using PHP?
- How to create a snippet in WordPress using PHP?
- How to use the WordPress REST API with PHP?
- How to run an SQL query in WordPress using PHP?
- How to create pagination in WordPress using PHP?
See more codes...