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
- Trying to remove post thumbnail with plugin
- Randomly Assign an Image’s Alt Text Based on Data From Post
- Passing the custom field values in the wp_get_current_user array function
- hook that when page is starting to load
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- Sort posts by custom fields value using dropdown menu
- How to change home or site url using action hooks or filter?
- Custom profile field with birthday. Troubles with
- ajax, right way to do it and make it works?
- WordPress – Display array data of a child
- Sending data from custom inputs in WordPress comment form in the admin notification email
- Edit incorrect password message WordPress
- Assign / update custom field value for all posts (How can I assign only to posts without custom field value?)
- wordpress allow user to edit user profile with custom fields
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Sort custom meta column by other meta value
- How to update custom field in WooCommerce
- Reload part of checkout on changed shipping method
- Trying to build simple deposit code that hooks into woocommerce
- Creating user status mode in WordPress
- Need Help Fixing My Iframes [closed]
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- get_post_meta not working on publishing
- Need help with Google drive API [closed]
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Remove metabox from WordPress menu editor page?
- Add a product to checkout via form
- Firing schema via code in functions.php doesn’t work
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Why ajax doesn’t work on certain wordpress hooks?
- Remove a div from RSS feed
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- user_profile_update_errors hook not executing
- Adding number to date not working [closed]
- Set meta field to publish date + 2 weeks
- How to add an arrow to menu items has submenus
- WordPress Gravatar filter is removing my custom attributes
- How can I add extra word in permalink when someone click download button?
- Error in custom php function doesn’t exist
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- Saving and Restoring a Canvas on A Individual User Basis
- Don’t insert if permalink is the same?
- Return a numerical function value in Customizer controls
- Adding widgets to my plugin page instead of WordPress dashboard
- Seach custom post type posts only by meta fields?
- How to use thumbnail size of image if I’m only using src to get image
- 3 Slashes appear after Apostrophe in custom fields after updating product-site
- how to retrieve a value if a checkbox is checked
- Trouble checking if custom woocommerce checkout field is empty or not
- Two queries for a WP_User_Query search work perfectly apart, but not together
- edit_comment_link is not showing for comment author
- Adding function to Genesis genesis_header [closed]
- Archive post by meta value + 24hours
- Modify custom field input data before creating a new post
- auto-populating custom nav with all items from custom post type
- how to make custom ajax handler?
- Are all hooks/functions tied to Kses meant for sanitization?
- Add / Update Custom Fields After Select Pictures in Media Window
- WordPress update_post_meta updating with empty meta_value field [closed]
- conditional logic for front-end custom field edits
- Trying to retrieve post meta
- Automatic Shortcode Creation with Custom Fields [closed]
- Custom field values to taxonomy terms
- How would an if statement surrounding a custom field with two variables (holding values) look like?
- How to add specific meta tags to head of cart and checkout pages in woocommerce?
- Custom Field IF/ELSE PHP
- Why does wp_head hook my functions to the beginning of my source code?
- Pass argument to event hook
- How to remove woocommerce_breadcrumb() from do_action( ‘woocommerce_before_main_content’ ); [closed]
- Which PHP page is the Default Posts Page
- Should `wp_login` be used since it’s deprecated?