get_post_class() WP 1.0
Retrieves the classes for the post div as an array.
The class names are many. If the post is a sticky, then the 'sticky' class name. The class 'hentry' is always added to each post. If the post has a post thumbnail, 'has-post-thumbnail' is added as a class. For each taxonomy that the post belongs to, a class will be added of the format '{$taxonomy}-{$slug}' - eg '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', with the list of class names, followed by $class parameter value, with the post ID as the last parameter.
Basis of: post_class()
1 time = 0.00616s = very slow | 50000 times = 10.72s = slow | PHP 7.0.2, WP 4.4.1
Hooks from the function
Return
String[]. Array of class names.
Usage
get_post_class( $class, $post_id );
- $class(string/string[])
- Space-separated string or array of class names to add to the class list.
Default: '' - $post_id(int/WP_Post)
- Post ID or post object.
Default: null
Changelog
Since 2.7.0 | Introduced. |
Since 4.2.0 | Custom taxonomy class names were added. |
Code of get_post_class() get post class WP 5.6
Related Functions
From tag: CSS classes
More from category: Other Theme Functions
- add_theme_support()
- bloginfo()
- body_class()
- current_theme_supports()
- get_custom_header_markup()
- get_custom_logo()
- get_header_image()
- get_header_image_tag()
- get_header_textcolor()
- get_header_video_url()
- get_page_templates()
- get_query_template()
- get_stylesheet()
- get_template()
- get_theme_mod()
- get_theme_mods()
- get_theme_root()
- has_custom_logo()
- has_header_image()
- has_header_video()
- is_child_theme()
- is_header_video_active()
- is_multi_author()
- post_class()
- register_nav_menu()
- register_nav_menus()
- register_theme_directory()
- remove_theme_mod()
- remove_theme_mods()
- remove_theme_support()
- search_theme_directories()
- set_theme_mod()
- single_month_title()
- the_custom_header_markup()