bbp_body_class

Use the above is_() functions to output a body class for each scenario.

Description

(array) bbp_body_class( (array) $wp_classes, (bool) $custom_classes = false ); 

Returns (array)

Body Classes

Parameters (2)

0. $wp_classes (array)
The wp classes.
1. $custom_classes — Optional. (bool) => false
The custom classes.

Usage

  1. if ( !function_exists( 'bbp_body_class' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/common/template.php'; 
  3.  
  4. // The wp classes. 
  5. $wp_classes = array(); 
  6.  
  7. // The custom classes. 
  8. $custom_classes = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_body_class($wp_classes, $custom_classes); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/common/template.php  
  1. function bbp_body_class( $wp_classes, $custom_classes = false ) { 
  2.  
  3. $bbp_classes = array(); 
  4.  
  5. /** Archives **************************************************************/ 
  6.  
  7. if ( bbp_is_forum_archive() ) { 
  8. $bbp_classes[] = bbp_get_forum_post_type() . '-archive'; 
  9.  
  10. } elseif ( bbp_is_topic_archive() ) { 
  11. $bbp_classes[] = bbp_get_topic_post_type() . '-archive'; 
  12.  
  13. /** Topic Tags ************************************************************/ 
  14.  
  15. } elseif ( bbp_is_topic_tag() ) { 
  16. $bbp_classes[] = bbp_get_topic_tag_tax_id(); 
  17. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug(); 
  18. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id(); 
  19. } elseif ( bbp_is_topic_tag_edit() ) { 
  20. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-edit'; 
  21. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug() . '-edit'; 
  22. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id() . '-edit'; 
  23.  
  24. /** Components ************************************************************/ 
  25.  
  26. } elseif ( bbp_is_single_forum() ) { 
  27. $bbp_classes[] = bbp_get_forum_post_type(); 
  28.  
  29. } elseif ( bbp_is_single_topic() ) { 
  30. $bbp_classes[] = bbp_get_topic_post_type(); 
  31.  
  32. } elseif ( bbp_is_single_reply() ) { 
  33. $bbp_classes[] = bbp_get_reply_post_type(); 
  34.  
  35. } elseif ( bbp_is_topic_edit() ) { 
  36. $bbp_classes[] = bbp_get_topic_post_type() . '-edit'; 
  37.  
  38. } elseif ( bbp_is_topic_merge() ) { 
  39. $bbp_classes[] = bbp_get_topic_post_type() . '-merge'; 
  40.  
  41. } elseif ( bbp_is_topic_split() ) { 
  42. $bbp_classes[] = bbp_get_topic_post_type() . '-split'; 
  43.  
  44. } elseif ( bbp_is_reply_edit() ) { 
  45. $bbp_classes[] = bbp_get_reply_post_type() . '-edit'; 
  46.  
  47. } elseif ( bbp_is_reply_move() ) { 
  48. $bbp_classes[] = bbp_get_reply_post_type() . '-move'; 
  49.  
  50. } elseif ( bbp_is_single_view() ) { 
  51. $bbp_classes[] = 'bbp-view'; 
  52.  
  53. /** User ******************************************************************/ 
  54.  
  55. } elseif ( bbp_is_single_user_edit() ) { 
  56. $bbp_classes[] = 'bbp-user-edit'; 
  57. $bbp_classes[] = 'single'; 
  58. $bbp_classes[] = 'singular'; 
  59.  
  60. } elseif ( bbp_is_single_user() ) { 
  61. $bbp_classes[] = 'bbp-user-page'; 
  62. $bbp_classes[] = 'single'; 
  63. $bbp_classes[] = 'singular'; 
  64.  
  65. } elseif ( bbp_is_user_home() ) { 
  66. $bbp_classes[] = 'bbp-user-home'; 
  67. $bbp_classes[] = 'single'; 
  68. $bbp_classes[] = 'singular'; 
  69.  
  70. } elseif ( bbp_is_user_home_edit() ) { 
  71. $bbp_classes[] = 'bbp-user-home-edit'; 
  72. $bbp_classes[] = 'single'; 
  73. $bbp_classes[] = 'singular'; 
  74.  
  75. } elseif ( bbp_is_topics_created() ) { 
  76. $bbp_classes[] = 'bbp-topics-created'; 
  77. $bbp_classes[] = 'single'; 
  78. $bbp_classes[] = 'singular'; 
  79.  
  80. } elseif ( bbp_is_favorites() ) { 
  81. $bbp_classes[] = 'bbp-favorites'; 
  82. $bbp_classes[] = 'single'; 
  83. $bbp_classes[] = 'singular'; 
  84.  
  85. } elseif ( bbp_is_subscriptions() ) { 
  86. $bbp_classes[] = 'bbp-subscriptions'; 
  87. $bbp_classes[] = 'single'; 
  88. $bbp_classes[] = 'singular'; 
  89.  
  90. /** Search ****************************************************************/ 
  91.  
  92. } elseif ( bbp_is_search() ) { 
  93. $bbp_classes[] = 'bbp-search'; 
  94. $bbp_classes[] = 'forum-search'; 
  95.  
  96. } elseif ( bbp_is_search_results() ) { 
  97. $bbp_classes[] = 'bbp-search-results'; 
  98. $bbp_classes[] = 'forum-search-results'; 
  99.  
  100. /** Clean up **************************************************************/ 
  101.  
  102. // Add bbPress class if we are within a bbPress page 
  103. if ( !empty( $bbp_classes ) ) { 
  104. $bbp_classes[] = bbpress; 
  105.  
  106. // Merge WP classes with bbPress classes and remove any duplicates 
  107. $classes = array_unique( array_merge( (array) $bbp_classes, (array) $wp_classes ) ); 
  108.  
  109. // Deprecated filter (do not use) 
  110. $classes = apply_filters( 'bbp_get_the_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes ); 
  111.  
  112. return apply_filters( 'bbp_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );