Note –
I recommend using the hook suggested by @Chip Bennett in another answer
Here’s the modified version of that filter –
function wpse_filter_post_class( $classes ) { $my_post_class = get_post_meta($post->ID, "your_meta_name"); if( $my_post_class != '' ) $classes[] = $my_post_class; return $classes; } add_filter( 'post_class', 'wpse_filter_post_class' );
You can setup a Custom fileds for that – See usage, then use get_post_meta()
function to fetch it and show where you want
Example –
<?php echo get_post_meta($post->ID, "your_meta_name", true)?>
This will output the class name set in the meta_key
.
OR ( Update #1 ) –
Pass the variable into Post Class
<?php $my_class = get_post_meta($post->ID, "your_meta_name") ?>
<div id="post-<?php the_ID(); ?>" <?php post_class( $my_class ); ?>>
Related Posts:
- How to make classes for posts?
- Is this the best (and only) option to style CSS for a given post type?
- Add a class to post title if a link ends with a certain extension
- Making a custom Pagination for multi page blog post
- Every second post different class in blog view
- How can I add a class to particular paragraphs in my post?
- Turn off display for custom sidebar post widget when on the post it’s displaying
- How to mark every 3rd post
- Is there a action hook for the “Empty Trash” button?
- Add a checkbox to post screen that adds a class to the title
- delete post also attachments
- Attach pdf file to custom post type
- Static posts page with home.php
- Delete Post Link to delete post, its meta and attachments
- Navigation link to specific user page
- How to edit wordpress RSS feed to show post title only
- Allow role to delete posts but block him the wp-admin
- Add custom fields to post programmatically
- Using Custom Posts with Metaboxes and Drop-downs
- Is it possible to have two different previews of a post (ie. two templates for one post)?
- Filter Posts By Tag
- Posts vs. Pages
- Dynamic carousel on individual posts
- How to add pagination in between post and comments?
- Set terms in a custom post
- I want to display custom text widgets for each post in the sidebar?
- Display posts styled exactly like default posts
- Print all the tags from a custom post type Please
- Display multiple custom taxonomy values on single custom post types page?
- Move first half of posts to one parent page, second half to the other page
- CSS: How can I show a photo beyond the template’s column, but contained within the browser window? [closed]
- Enable Comments Box On Custom Post Type
- How can i limit the number of posts created per category?
- Responsive images with custom image size
- Can I search posts and pages for css classes?
- Take a received feedback item, turn it into a post
- Getting value from get_post_custom
- Admin – create custom post status and display above table
- Set Default Category to Username
- show custom post type category dropdown sorting result on same page
- Is there a way to specify an extra class for a post or page with no title?
- “about us”, ” contact” sections should be article(post) or page in the simple small Business website?
- Customize rel=canonical tag for single blog post
- disable Tab post on nav-menus page (Admin)
- Make a vertical dynamic list of posts in alphabetically order and in columns [closed]
- Best Way to Add UnEditable HTML to Posts
- How to make different custom post layouts?
- How safe is it to delete old posts edits to save database space?
- Two Custom Post Types with Identical Articles Competing for the same Slug
- Is codex right on deleting post?
- if in category but only with post meta
- How to get different Related Posts
- My Custom Post Type Still Using index.php
- l accidentally permanently deleted a Draft. There’s any way I can recover it?
- How do I switch css class on post
- Inserting an example of the last 3 post on to the homepage
- wordpress add field to post_class
- Can WordPress handle following functionalities?
- Get a term each custom post type
- Getting post and attached image from subdomain
- Custom post type slideshow background images to insert in a plugin
- Locally change the font family [closed]
- YARPP php question
- Right align a youtube video
- Help on conditional statement to accompany wp_insert_post function please?
- How to allow arbitrary inline CSS in posts?
- Alt text attributes not showing over portfolio images
- Adding an option to post editor to show a site disclaimer or message
- Search results for ACF data
- Css and function issue on author archive page
- WordPress Recent Post with the badge “New” on the side of the title post
- Redirect to custom post if custom archive page has just one result?
- Multiple posts in one page
- I have two post types in the same query, how can I use CSS to select only one post type?
- delete post hook not being fired when deling in wordpress dashboard admin
- WordPress Delete Users from backend doesn’t work
- Is it possible to make a custom post that adds multiple pages?
- Custom post styling per category?
- Hook To Get All Posts Deleted
- Meta boxes not saving
- Custom Select Query pagination not working properly
- Custom URL Structure for posts with subcategories
- How to show the posts list into a static page? Problems to use the loop into a static page
- Adding The Post Template Dropdown to WP-Admin
- wordpress paginate, link to the right page
- Allow users to create their own page/s
- 404 for some custom taxonomy not ALL taxonomy
- Add default content to post (for specific category)
- Setting default category for display
- WordPress strips some attributes for author posts
- How to Do Custom Fields to Output a Definition List
- Display one post randomly from category on home page
- Deleting first four characters from all Post Titles
- Deleling wordpress posts permanently still have IDs
- Taxonomy Category category.php not working
- Change a div background color on Post ID
- Post’s arent displaying
- Can I get custom post items in select box (dropdown)
- How to have 2 posting pages on a blog
- Notify/check if the content of a custom gutenberg block has changed on save_post