swest

add-custom-body-class.php

Mar 3rd, 2025
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. <?php
  2. // add custom body class for dontpaniclabs.com
  3. add_filter( 'body_class', 'dpl_add_custom_body_class' );
  4.  
  5. function dpl_add_custom_body_class( $classes ) {
  6.    $classes[] = 'dpl';
  7.    return $classes;
  8. }
  9.  
  10. // https://sridharkatakam.com/add-page-slug-body-class-static-pages-wordpress/
  11. add_filter( 'body_class', 'dpl_body_class_for_pages' );
  12. /**
  13.  * Adds a css class to the body element
  14.  *
  15.  * @param  array $classes the current body classes
  16.  * @return array $classes modified classes
  17.  */
  18. function dpl_body_class_for_pages( $classes ) {
  19.  
  20.   if ( is_singular( 'page' ) ) {
  21.     global $post;
  22.     $classes[] = 'dpl-page-' . $post->post_name;
  23.   }
  24.   return $classes;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment