On this page
post_class( string|string[] $class = '', int|WP_Post $post = null )
Displays the classes for the post container element.
Parameters
$classstring|string[] Optional-
One or more classes to add to the class list.
Default:
'' $postint|WP_Post Optional-
Post ID or post object. Defaults to the global
$post.Default:
null
Source
File: wp-includes/post-template.php. View all references
function post_class( $class = '', $post = null ) {
// Separates classes with a single space, collates classes for post DIV.
echo 'class="' . esc_attr( implode( ' ', get_post_class( $class, $post ) ) ) . '"';
}
Related
Uses
| Uses | Description |
|---|---|
| get_post_class() wp-includes/post-template.php | Retrieves an array of the class names for the post container element. |
| esc_attr() wp-includes/formatting.php | Escaping for HTML attributes. |
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/post_class