W3cubDocs

/WordPress

post_class( string|string[] $css_class = , int|WP_Post $post = null )

Displays the classes for the post container element.

Parameters

$css_classstring|string[]optional
One or more classes to add to the class list.

Default:''

$postint|WP_Postoptional
Post ID or post object. Defaults to the global $post.

Default:null

Source

function post_class( $css_class = '', $post = null ) {
	// Separates classes with a single space, collates classes for post DIV.
	echo 'class="' . esc_attr( implode( ' ', get_post_class( $css_class, $post ) ) ) . '"';
}

Changelog

Version Description
2.7.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/post_class