post_class

Display the classes for the post div.

Description

post_class( (string) $class = '', (null) $post_id = null ); 

Parameters (2)

0. $class — Optional. (string) => ''
One or more classes to add to the class list.
1. $post_id — Optional. (null) => null
Post ID or post object. Defaults to the global $post..

Usage

  1. if ( !function_exists( 'post_class' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-template.php'; 
  3.  
  4. // One or more classes to add to the class list. 
  5. $class = ''; 
  6.  
  7. // Optional. Post ID or post object. Defaults to the global `$post`. 
  8. $post_id = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = post_class($class, $post_id); 
  12.  

Defined (1)

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

/wp-includes/post-template.php  
  1. function post_class( $class = '', $post_id = null ) { 
  2. // Separates classes with a single space, collates classes for post DIV 
  3. echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';