What it does
post_class
adds classes to the posts on a post by post basis, usually adding them to some kind of post “wrapper”. This allows for the targeting of posts with CSS rules according to various criteria– category, tag, sticky, format, etc. That is, theme authors, plugin authors, and individual users can write CSS rules based on the classes added by post_class
and get very fine grained control over layout.
Why you want it
While I am not a canonical source, I am sure it is required according to the WordPress Theme guidelines to ensure a minimal functionality across themes. If you aren’t submitting your theme to the WordPress repo you can do what you want. There are no WordPress Theme Police to track you down and spank you, but post_class
and the related body_class
are very useful and easy to implement. I see no reason not to use them.
Related Posts:
- WordPress post arrangement using post_class
- Should all references to a text domain be to my current theme?
- My wordpress site memory exhausted more than 1GB trying to debug with default
- Sizing screenshot.png without losing aspect ratio
- How to add CSS class to custom logo?
- Should `get_template_directory_uri()` be escaped?
- How To Add New Option Types To Option Tree?
- Page template in two level deep folder
- Automatic Updates For Private And Commercial Themes?
- Child Theme not loading parent CSS
- What can I hook into after_setup_theme?
- Where do I find the functions triggered within a hook?
- Use of undefined constant FS_CHMOD_DIR – assumed ‘FS_CHMOD_DIR’
- Registering Sidebars and Sidebar Widgets. Sidebar Widgets Not Displaying
- Is it possible to display the admin bar while in the Theme Customizer?
- How do I get a parent theme modification from a child theme?
- Removing the default sidebar from admin panel
- how to pull wordpress post comments to a external page
- index.php is not loaded for single posts
- Why use while over if in single wordpress posts?
- WordPress website loads but is not displayed until page scrolled
- wp_enqueue_scripts not called on search page?
- How to use bloginfo( ‘template_directory’ ) in array
- How to set page template on front using starter content?
- Different Admin Theme – Based on Role?
- Theme Customizer not loading
- Is it a good idea to make whole theme widgetized?
- Single Theme folder for Multiple WordPress
- Override Constants in Child theme
- How i can get widgets areas working in customizer?
- Cutomize Colors utility: How to add more configurable colors to a theme
- Where is definied the theme location for the main menu in a WordPress template?
- How to disable automatic colors in the Twenty Twenty theme?
- Removing feeds from header using a function?
- I want to get the home root path
- How to add code in the content area in a WordPress theme?
- How to add theme support?
- Translation Issue with WordPress Theme Check in comment_form function
- Using esc_url with a hard coded url
- Broken template went invisible
- WordPress theme switcher
- Limitations when modifying wp_title with a filter
- How to edit theme functions file to modify pagination?
- WP_bootstrap_Navwalker_issue [closed]
- Font Awesome 5 Free – far working but fas is not? [closed]
- correct tags for validating input types
- Renaming a theme so it aids SEO and the theme used is hidden
- Integrate WooCommerce theme with a WordPress theme [closed]
- WordPress 3.8 Backend Admin Color Scheme add more scheme how to do?
- Theme thumbnail in dashboard
- How to change the theme directory uri for localhost?
- Will my site get messed up when the wordpress theme updates if I edited the html code in the editor to change footer?
- How to correctly enqueue the parent and child theme stylesheets in the creation of a child theme? [duplicate]
- Managing WordPress Theme
- featured content: which area does this cover [closed]
- CSS class on last post in loop ( custom query )
- Which cache is kicking
- searchform.php doesn’t work properly
- Customizer: get_preview_url() inside customize_save_after hook
- Shortcodes do not work in own template
- Adding Bootstrap to WordPress TwentySixteen Theme
- Is there a way to switch to another theme?
- New to WordPress – Read the Codex, Other Docs; Still Confused
- Following/tracing page construction through theme PHP
- When trying to set title, not sure how to edit it for different pages
- Post archives link yields a 404 Not Found
- Get video from the post on homepage
- static front page ONLY for certain themes?
- How to add cropped custom header image?
- Open portfolio image in light box
- WordPress Themes Directory: Template which hits the standards?
- How to change a local wordpress installation xml export file urls? and change them to what if you don’t have a live website?
- Any way to change/add to the theme name dynamically?
- Let user to upload multiple time
- How to make menus, footer, sidebars multi language
- Different WP Rest API custom endpoints across different themes
- How to generate a rtl.css file for themes?
- change wordpress website logo url [duplicate]
- register_theme_directory() sees custom themes directory, but blank frontend
- hide/show a div in wordpress
- Providing updates to your WordPress theme
- How one category can have different fields?
- How to create multiple pages in a client theme?
- How do child themes work?
- Using Customizer value in an external PHP file inside a theme
- Import from HubSpot COS into WordPress 4?
- Theme customizer live preview JS- Trying to bind to an html image url without luck
- Theme automatically inserting “more” tag on every post
- How get the 10 most viewed pages (not post)
- adding navigation to genesis themes
- Using wp_enqueue_script with social media buttons?
- Undefined index: debuging error for theme option template snippet
- Show post thumbnail only if it exists using timthumb
- Purchased Theme to Custom Made Theme? [closed]
- How to make website with many template that active [closed]
- Image Size wrong during upload
- How to create full header but keep content narrow
- Correct way to make a custom block theme responsive
- What is the point of using the front-page.php template? [closed]
- Full site editing templates folder vs block-templates