Adding a class to the body tag for all pages and posts in WordPress
Add a class for all pages and posts in WordPress. For these purposes in CMS i added a special function add_body_classes(). This function can take an array with class names, which will later be added to the body tag.
Function Example:
1 2 3 4 5 6 7 |
add_filter('body_class','add_body_classes'); function add_body_classes($classes) { $classes[] = 'my-class-one'; $classes[] = 'my-class-two'; $classes[] = 'my-class-three'; return $classes; } |
Need to check, so that in your site template in the tag body the following function has been added. It is usually set by default in templates..
An example of deriving classes through a function.
1 |
<body <?php body_class(); ?>> |
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.