Advertisement
brooklyndesignstudio

Add Classes for Custom Post Types

Jun 16th, 2021
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.49 KB | None | 0 0
  1. // Adds classes for custom post types to body_class() and post_class()
  2. function fb_add_body_class( $class ) {
  3.     $post_type = 'my_example_post_type'; // the Post Type
  4.  
  5.     if ( get_query_var('post_type') === $post_type ) { // only, if post type is active
  6.         $class[] = $post_type;
  7.         $class[] = 'type-' . $post_type;
  8.     }
  9.  
  10.     return $class;
  11. }
  12. add_filter( 'body_class', 'fb_add_body_class' );
  13.  
  14. or
  15.  
  16. add_filter( 'post_class', 'fb_add_body_class' );
  17. Example: <div <?php post_class('class-name'); ?>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement