wppaste
WordPress

get_post_class( string|string[] $css_class = '', int|WP_Post|null $post = null ): string[]

Since
2.7.0, 4.2.0
Source
wp-includes/post-template.php:494
Retrieves an array of the class names for the post container element.

Description

The class names are many:

  • If the post has a post thumbnail, has-post-thumbnail is added as a class.
  • If the post is sticky, then the sticky class name is added.
  • The class hentry is always added to each post.
  • For each taxonomy that the post belongs to, a class will be added of the format {$taxonomy}-{$slug}, e.g. category-foo or my_custom_taxonomy-bar.
    The post_tag taxonomy is a special case; the class has the tag- prefix instead of post_tag-.

All class names are passed through the filter, 'post_class', followed by $css_class parameter value, with the post ID as the last parameter.

Compatibility

WordPress
since 4.2.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$css_classstring|string[]optional
Space-separated string or array of class names to add to the class list. Default empty.Default: ''
$postint|WP_Post|nulloptional
Post ID or post object.Default: null

Return value

string[]
Array of class names.

Performance profile

How much work a call to get_post_class() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_post().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
11–141

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 216.

Plugin surface
2 hooks

Third-party callbacks on 'post_class_taxonomies', 'post_class' run inside this call, and their cost is not bounded by anything here.

Called by
4

4 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()one call below get_post_class()
  • cacheobject cachewp_cache_add()one call below get_post_class()

Further down the call graph this can also reach serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 54 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost get_post_class() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always11get_post()
!post_type_supports() && !current_theme_supports() && !is_sticky()93–99get_post(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), is_sticky(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
!post_type_supports() && current_theme_supports() && !has_post_thumbnail() && !is_sticky()99–105get_post(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
!post_type_supports() && !current_theme_supports() && is_sticky() && !is_home()99–107get_post(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
is_array($css_class) && is_admin() && !post_type_supports() && empty($post) && !current_theme_supports() && !is_sticky()100–101get_post(), array_map(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), is_sticky(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !current_theme_supports() && !is_sticky()102–108get_post(), is_admin(), post_type_supports(), get_post_format(), post_password_required(), current_theme_supports(), is_sticky(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
!post_type_supports() && !current_theme_supports() && is_sticky() && is_home() && !is_paged()102–108get_post(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_paged(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
!post_type_supports() && !current_theme_supports() && is_sticky() && is_home() && is_paged()102–110get_post(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_paged(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
!post_type_supports() && current_theme_supports() && has_post_thumbnail() && !is_sticky()103–112get_post(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
!post_type_supports() && current_theme_supports() && !has_post_thumbnail() && is_sticky() && !is_home()105–113get_post(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), is_home(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && is_wp_error() && !current_theme_supports() && !is_sticky()106–112get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), post_password_required(), current_theme_supports(), is_sticky(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
is_array($css_class) && is_admin() && !post_type_supports() && empty($post) && current_theme_supports() && !has_post_thumbnail() && !is_sticky()106–107get_post(), array_map(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
42 further outcomes, up to 141 instructions
is_array($css_class) && is_admin() && !post_type_supports() && empty($post) && !current_theme_supports() && is_sticky() && !is_home()106–109get_post(), array_map(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && current_theme_supports() && !has_post_thumbnail() && !is_sticky()108–114get_post(), is_admin(), post_type_supports(), get_post_format(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
!post_type_supports() && current_theme_supports() && !has_post_thumbnail() && is_sticky() && is_home() && !is_paged()108–114get_post(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), is_home(), is_paged(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !current_theme_supports() && is_sticky() && !is_home()108–116get_post(), is_admin(), post_type_supports(), get_post_format(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
!post_type_supports() && current_theme_supports() && !has_post_thumbnail() && is_sticky() && is_home() && is_paged()108–116get_post(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), is_home(), is_paged(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
is_array($css_class) && is_admin() && !post_type_supports() && empty($post) && !current_theme_supports() && is_sticky() && is_home() && !is_paged()109–110get_post(), array_map(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_paged(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
!post_type_supports() && current_theme_supports() && has_post_thumbnail() && is_sticky() && !is_home()109–120get_post(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), is_home(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
is_array($css_class) && is_admin() && !post_type_supports() && empty($post) && !current_theme_supports() && is_sticky() && is_home() && is_paged()109–112get_post(), array_map(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_paged(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !current_theme_supports() && is_sticky() && is_home() && !is_paged()111–117get_post(), is_admin(), post_type_supports(), get_post_format(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_paged(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !is_wp_error() && !current_theme_supports() && !is_sticky()111–117get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), sanitize_html_class(), post_password_required(), current_theme_supports(), is_sticky(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !current_theme_supports() && is_sticky() && is_home() && is_paged()111–119get_post(), is_admin(), post_type_supports(), get_post_format(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_paged(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && current_theme_supports() && has_post_thumbnail() && !is_sticky()112–121get_post(), is_admin(), post_type_supports(), get_post_format(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && is_wp_error() && current_theme_supports() && !has_post_thumbnail() && !is_sticky()112–118get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
!post_type_supports() && current_theme_supports() && has_post_thumbnail() && is_sticky() && is_home() && !is_paged()112–121get_post(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), is_home(), is_paged(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && is_wp_error() && !current_theme_supports() && is_sticky() && !is_home()112–120get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
!post_type_supports() && current_theme_supports() && has_post_thumbnail() && is_sticky() && is_home() && is_paged()112–123get_post(), is_admin(), post_type_supports(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), is_home(), is_paged(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && current_theme_supports() && !has_post_thumbnail() && is_sticky() && !is_home()114–122get_post(), is_admin(), post_type_supports(), get_post_format(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), is_home(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && is_wp_error() && !current_theme_supports() && is_sticky() && is_home() && !is_paged()115–121get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_paged(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && is_wp_error() && !current_theme_supports() && is_sticky() && is_home() && is_paged()115–123get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_paged(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && is_wp_error() && current_theme_supports() && has_post_thumbnail() && !is_sticky()116–125get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && current_theme_supports() && !has_post_thumbnail() && is_sticky() && is_home() && !is_paged()117–123get_post(), is_admin(), post_type_supports(), get_post_format(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), is_home(), is_paged(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !is_wp_error() && current_theme_supports() && !has_post_thumbnail() && !is_sticky()117–123get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), sanitize_html_class(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && current_theme_supports() && !has_post_thumbnail() && is_sticky() && is_home() && is_paged()117–125get_post(), is_admin(), post_type_supports(), get_post_format(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), is_home(), is_paged(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !is_wp_error() && !current_theme_supports() && is_sticky() && !is_home()117–125get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), sanitize_html_class(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && current_theme_supports() && has_post_thumbnail() && is_sticky() && !is_home()118–129get_post(), is_admin(), post_type_supports(), get_post_format(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), is_home(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && is_wp_error() && current_theme_supports() && !has_post_thumbnail() && is_sticky() && !is_home()118–126get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), is_home(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !is_wp_error() && !current_theme_supports() && is_sticky() && is_home() && !is_paged()120–126get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), sanitize_html_class(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_paged(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !is_wp_error() && !current_theme_supports() && is_sticky() && is_home() && is_paged()120–128get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), sanitize_html_class(), post_password_required(), current_theme_supports(), is_sticky(), is_home(), is_paged(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && current_theme_supports() && has_post_thumbnail() && is_sticky() && is_home() && !is_paged()121–130get_post(), is_admin(), post_type_supports(), get_post_format(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), is_home(), is_paged(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && is_wp_error() && current_theme_supports() && !has_post_thumbnail() && is_sticky() && is_home() && !is_paged()121–127get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), is_home(), is_paged(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !is_wp_error() && current_theme_supports() && has_post_thumbnail() && !is_sticky()121–130get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), sanitize_html_class(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && current_theme_supports() && has_post_thumbnail() && is_sticky() && is_home() && is_paged()121–132get_post(), is_admin(), post_type_supports(), get_post_format(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), is_home(), is_paged(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && is_wp_error() && current_theme_supports() && !has_post_thumbnail() && is_sticky() && is_home() && is_paged()121–129get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), is_home(), is_paged(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && is_wp_error() && current_theme_supports() && has_post_thumbnail() && is_sticky() && !is_home()122–133get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), is_home(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !is_wp_error() && current_theme_supports() && !has_post_thumbnail() && is_sticky() && !is_home()123–131get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), sanitize_html_class(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), is_home(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && is_wp_error() && current_theme_supports() && has_post_thumbnail() && is_sticky() && is_home() && !is_paged()125–134get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), is_home(), is_paged(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && is_wp_error() && current_theme_supports() && has_post_thumbnail() && is_sticky() && is_home() && is_paged()125–136get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), is_home(), is_paged(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !is_wp_error() && current_theme_supports() && !has_post_thumbnail() && is_sticky() && is_home() && !is_paged()126–132get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), sanitize_html_class(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), is_home(), is_paged(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !is_wp_error() && current_theme_supports() && !has_post_thumbnail() && is_sticky() && is_home() && is_paged()126–134get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), sanitize_html_class(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_sticky(), is_home(), is_paged(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !is_wp_error() && current_theme_supports() && has_post_thumbnail() && is_sticky() && !is_home()127–138get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), sanitize_html_class(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), is_home(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !is_wp_error() && current_theme_supports() && has_post_thumbnail() && is_sticky() && is_home() && !is_paged()130–139get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), sanitize_html_class(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), is_home(), is_paged(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()
post_type_supports() && !is_wp_error() && current_theme_supports() && has_post_thumbnail() && is_sticky() && is_home() && is_paged()130–141get_post(), is_admin(), post_type_supports(), get_post_format(), is_wp_error(), sanitize_html_class(), post_password_required(), current_theme_supports(), has_post_thumbnail(), is_attachment(), is_sticky(), is_home(), is_paged(), is_admin(), get_taxonomies(), apply_filters(), array_map(), apply_filters(), array_unique(), array_values()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev21611–14126
8.521611–14126
8.421611–141265 fewer instructions than PHP 8.3
8.322193–14126
8.222193–14126
8.122193–14126
7.422193–14126

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 2

2 hooks fire while get_post_class() runs, in this order:

  1. apply_filters( post_class_taxonomies )filterline 572 (+78 into the body)

    Filters the taxonomies to generate classes for each individual term.

  2. apply_filters( post_class )filterline 607 (+113 into the body)

    Filters the list of CSS class names for the current post.

Uses · 17

Show all 17
  • is_paged()Determines whether the query is for a paged result and not for the first page.
  • get_taxonomies()Retrieves a list of registered taxonomy names or objects.
  • apply_filters()Calls the callback functions that have been added to a filter hook.
  • is_object_in_taxonomy()Determines if the given object type is associated with the given taxonomy.
  • get_the_terms()Retrieves the terms of the taxonomy that are attached to the post.

Used by · 4

Source code

function get_post_class( $css_class = '', $post = null ) {	$post = get_post( $post ); 	$classes = array(); 	if ( $css_class ) {		if ( ! is_array( $css_class ) ) {			$css_class = preg_split( '#\s+#', $css_class );		}		$classes = array_map( 'esc_attr', $css_class );	} else {		// Ensure that we always coerce class to being an array.		$css_class = array();	} 	if ( ! $post ) {		return $classes;	} 	$classes[] = 'post-' . $post->ID;	if ( ! is_admin() ) {		$classes[] = $post->post_type;	}	$classes[] = 'type-' . $post->post_type;	$classes[] = 'status-' . $post->post_status; 	// Post Format.	if ( post_type_supports( $post->post_type, 'post-formats' ) ) {		$post_format = get_post_format( $post->ID ); 		if ( $post_format && ! is_wp_error( $post_format ) ) {			$classes[] = 'format-' . sanitize_html_class( $post_format );		} else {			$classes[] = 'format-standard';		}	} 	$post_password_required = post_password_required( $post->ID ); 	// Post requires password.	if ( $post_password_required ) {		$classes[] = 'post-password-required';	} elseif ( ! empty( $post->post_password ) ) {		$classes[] = 'post-password-protected';	} 	// Post thumbnails.	if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ! is_attachment( $post ) && ! $post_password_required ) {		$classes[] = 'has-post-thumbnail';	} 	// Sticky for Sticky Posts.	if ( is_sticky( $post->ID ) ) {		if ( is_home() && ! is_paged() ) {			$classes[] = 'sticky';		} elseif ( is_admin() ) {			$classes[] = 'status-sticky';		}	} 	// hentry for hAtom compliance.	$classes[] = 'hentry'; 	// All public taxonomies.	$taxonomies = get_taxonomies( array( 'public' => true ) ); 	/**	 * Filters the taxonomies to generate classes for each individual term.	 *	 * Default is all public taxonomies registered to the post type.	 *	 * @since 6.1.0	 *	 * @param string[] $taxonomies List of all taxonomy names to generate classes for.	 * @param int      $post_id    The post ID.	 * @param string[] $classes    An array of post class names.	 * @param string[] $css_class  An array of additional class names added to the post.	*/	$taxonomies = apply_filters( 'post_class_taxonomies', $taxonomies, $post->ID, $classes, $css_class );

Changelog

Introduced in 2.7.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.0.4
Parameter $post retyped from int|WP_Post to int|WP_Post|null.verified against source
4.2.0
Custom taxonomy class names were added.from the docblock
2.7.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/post-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.