In the header.php
template, you cannot access the $post
variable.
So you will have to map it using $wp_query
, as mentioned on ACF forum here.
Try this:
<?php
global $wp_query;
$post = $wp_query->post;
$background = get_field('background', $post->ID);
?>
<style>
.site-header {
background: url(<?php echo $background; ?>) no-repeat center;
background-size: cover;
}
</style>
Related Posts:
- ACF Repeater loops and resets – where is the reset_rows() documentation? [closed]
- Remove comma from last item output from loop
- the_content() seems to block my ACF-code
- How do I go about looping through a advanced custom field on a particular page inside of another page
- Using an ACF field from a page within a post loop?
- How to hook into container
- Cannot retieve the_content() and the_author() – both returning empty strings
- Distribute Gallery Images Every nth in Loop
- ACF – add a group inside a repeater [closed]
- While loop with bootstrap [closed]
- How to create a multidimensional array with multiple loops
- Loop through ACF taxonomies and output associated posts
- Blank content php code not parsing advanced custom fields gallery add-on [closed]
- ACF: display custom filed of CPT into the loop
- Use ACF Category Image for all Taxonomy Archive Views
- Need to while loop and display contents in the subfield of a group field given by ACF
- Add Search and Filter functionality to custom loop
- ACF field not appearing correctly in loop
- Can’t see custom field after the Loop [closed]
- While loop inside another while loop
- ACF loops false value with repeater and checkbox
- Jquery Slider for profile template
- Get excerpt using get_the_excerpt outside a loop
- Should I use loop in the single.php file?
- how to upload image using wp_handle_upload
- wp_list_categories: get latest featured_image of category
- WordPress Alphabetical Glossary close div in loop
- How to make multiple Column in archive Page?
- Exclude filter on front page
- category__not_in — anyway to use category name instead of id?
- Filtering posts by multiple taxonomies
- Exclude first 2 posts with meta_key from loop
- Make a custom loop inside single.php with pagination
- Why do I get `Call to a member function have_posts() on a non-object `? [closed]
- Help with Changing loop.php?
- How to split a loop into two columns
- Category Ajax call
- Change front-page layout after x amount of posts ( while in the same loop)
- Transient loop issue
- popular post weekly and monthly
- How can i use the same template file with a widget and category loop?
- WordPress Loop inside Loop?
- angularjs not displaying all posts
- query_posts() vs get_posts() multiple loops [duplicate]
- Latest Post Styled Different Than other Posts
- single.php – how to mark current page in the loop
- How to order by multiple fields using standard query_posts?
- Get 1 more post in loop
- Make loop alphabetical
- How to check if a product is purchased within the last 365 days before displaying something
- How do I get my loop.php to properly paginate?
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- Hiding a row in the loop if empty
- How to display first post
- Pagination on custom post type on front-page.php
- get_template_part() Not Working in Loop
- get_delete_post_link() inside Loop stubbornly returns nothing
- CPT while loop not working
- Problem with Front-Page.php loading recent posts
- Comments_template doesn’t work
- Get markup for post without loading into the template
- Where to add offset?
- How to synchronize The Loop with the max post per page?
- How to add a byline to all the pages?
- Displaying member join date on page
- Ascending order has strange effects on wordpress loop
- get post images to link to external sources
- Set depth of pages to fetch
- ACF: How can I publish values of ACF fields in a loop while using wp_query?
- ACF – Get ID of relationship field in flexible content
- Can’t limit posts_per_page in loop
- Slug is changing when I use WP_Query in a metabox of a post
- Display related post content and custom field content
- How to execute a user loop with shortcode
- Custom loop not working in singular.php, working in other pages
- Loop Posts Outside of WordPress Installation
- Strange problem with wp_get_attachment_image_src database (db) query count
- How to include posts from one category, into a separate category of posts?
- how do i make this loop work
- Issue in If else condition [closed]
- Making a specific page wordpress compatable that is not index
- Can’t print out returned value
- change the_content images for different sizes (Desktop, tablet, mobile)?
- the_post_thumbnail unless video id is added
- My Query is getting the wrong data
- display only parent replies count in index.php
- using the loop on a page
- Home page loop with pagination problem
- WooCommerce custom loop pagination on front page
- Eliminate duplicates in a foreach loop [closed]
- Tag custom loop show posts
- I want the first post on my home page to be lengthier than the rest (example included)
- Output ACF field dynamicaly within a taxonomy loop [closed]
- Loop with Custom Post Type Taxonomies and Interstitial Code
- Question about custom plugin
- loop mix my child-category and parent-category
- Fix html inside a for loop [closed]
- Display all posts in a page code for template
- Insert multiple custom components after x-number of posts
- Hook in the loop after the first post