Home › Forums › General Issues › Post and category image background › Reply To: Post and category image background
I would imagine something like the bellow would resolve this issue but it doesn’t:
if ( get_field('background_image') ) {
// set this to the handle of one of your stylesheets
$handle = 'main-styles';
$queried_object = get_queried_object();
if (isset($queried_object->ID)) {
$post_id = $queried_object->ID;
} else if (isset($queried_object->term_id)) {
$post_id = $queried_object->taxonomy.'_'.$queried_object->term_id;
}
$bg_image = get_field('background_image', $post_id);
$css = "body { background-image: url('$bg_image')!important; }";
wp_add_inline_style( $handle, $css );
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.