You want to use body_class
filter.
function prefix_add_body_class( $classes ) {
global $post;
// good to check
if( ! is_single() || 'post' !== get_post_type() ) {
return $classes;
}
$btag = get_post_meta( $post->ID, 'tagbody', true );
if ( empty( $btag ) ) {
return $classes;
}
$classes[] = $btag;
return $classes;
}
add_filter( 'body_class', 'prefix_add_body_class' )
EDIT:
You wrote me in the comments that the theme is your own theme. So you don’t need to do it via a filter. Just do it right in your theme.
Edit the header.php file like this.
// some code above
$classes = array();
if( is_single() && 'post' === get_post_type() ) {
$btag = get_post_meta( $post->ID, 'tagbody', true );
if( ! empty( $btag ) ) {
$classes[] = $btag;
}
}
?>
<body <?php body_class( $classes ); ?>>
<?php
// some code below
Related Posts:
- How to update custom fields using the wp_insert_post() function?
- How to display multiple Post meta_key/meta_values by SQL query
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- How to use multiple query with same meta key
- How can update custom meta for all posts
- Use ajax to update_post_meta
- how to increase custom post value by one most efficiently?
- How can I create a list of page titles from custom meta values?
- Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- Is it possible to retrieve all posts with a certain value for metadata?
- Non-Closing PHP Query in WordPress Loop
- how to get serialized post meta
- WordPress loop by meta key that is an array? and how loop multiple arrays
- How to store multiple custom meta box
- Order a WP_Query by meta value where the value is an array
- Define category ID using get_post_meta
- Hide a div when a custom field is empty
- WordPress stripping out custom field tags
- Order category posts by last word of custom field
- Add a “custom field” to a category that can be retrieved when viewing the category page with get_post_meta
- Display custom field value in woocommerce variable product via jQurey
- How to update custom fields when post is published?
- How do I get the value of a current user’s custom field?
- WP post meta – for loop inside for loop
- When working with a post, almost all wp_postmeta are deleted
- Updating Lat and Lng of posts automatically gives sporadic results
- If custom field doesn’t exist, or exists and it’s true show title?
- Metadata on the WP_Post object
- Using register_activation_hook in classes
- Get meta_id along with meta_key and meta_value
- How can merge two arrays values in one array and save in database
- How to handle a custom form in wordpress to submit to another page?
- post meta data clearing on autosave
- How to Remove a Filter from the Admin List Table?
- Compare two meta key values against each other inside the get_posts array?
- Woocommerce, recognize the loop of related products
- Removing WordPress profile fields from non-admins
- Show custom field if it exists, and show different elements if it doesn’t
- Change description on specific WooCommerce product status change
- Custom field value not saving when it contains a URL?
- How to add a second ‘place order’ button in WooCommerce [closed]
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- tracking number field in Woocommerce order [closed]
- Sort posts by custom fields value using dropdown menu
- Creating user status mode in WordPress
- Need Help Fixing My Iframes [closed]
- Add a product to checkout via form
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Return a numerical function value in Customizer controls
- Trouble checking if custom woocommerce checkout field is empty or not
- edit_comment_link is not showing for comment author
- Adding function to Genesis genesis_header [closed]
- Add / Update Custom Fields After Select Pictures in Media Window
- Remove the last X characters of a custom field value
- Password minimum length in personal subscription [closed]
- Why are the details of my todo not saving?
- Theme activation hook in php class
- Can’t save php string to a custom field
- Remove empty terms from array, sort alphabetically, update back to repeating field
- WordPress yoast seo plugin – parse snippet var in meta description
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- Handling repeater data
- How to add data to a custom field at the wp_users table?
- Using rules in Posts
- Save the value of a wp_dropdown_pages
- Add a counter for mouseovers (custom field)
- Show field if it has contents on Advanced Custom Fields
- the_meta – no get_the_meta query?
- Dynamically added custom fields not displayed on WooCommerce email notifications
- get value from get_post_meta then reuse it in another get_post_meta
- How can I add diffrent editable text fields?
- Include custom fields in search
- update_term_meta() only updating once on certain meta keys
- Loop for recently (updated_post_meta) posts?
- How to edit post meta data before publishing the post it self wordpress?
- Using zip code to display custom data in Admin Order Details
- Generating 3 random numbers and saving them in database
- ACF – Can’t get custom post type by taxonomy
- get Woocommerce product format json for WP_Query
- Is there an option to execute javascript file only on plugin activation
- update_post_meta Not Processing Array Data (Not Sure What I Am Missing)
- How do I remove an action hook inside a class that is called by another class?
- Hook into all password resets in WordPress and get password before hashing?
- What syntax is this? “{{post.price}}”
- Why transition_post_type hook is called twice for the same post?
- How to get the first letter from custom field?
- Meta box not saving spaces
- WordPress HTML Helper
- custom field meta-box with dropdown/autocomplete
- If Elseif Query
- get_post_meta is always empty when I use wp_mail
- Add custom fields after post/page title
- Display custom meta box in my template file
- How to display the date under the post title?
- Too many if’s and else if’s ?? – Must be better way [closed]
- Advanced Custom Fields Show PHP in Text Areas
- understanding wp_next_scheduled
- Convert custom field date format to “WordPress default”
- How to execute a shortcode within a custom field?