Home Forums Front-end Issues Use acf field from post in header


Use acf field from post in header

  • Is there any way to get data from a block into the header?

    I have a banner block that is at the top of almost every page. It contains, among other things, an image to display. I’d like to be able to add a <link rel="preload" image=...> tag in my header to speed up the display of the image and reduce LCP.

    Is there a way to do this? I know that if I move my block data to the page level, I can get it to work, but I’d rather not do that. I’d still like to use it as a normal block that may or may not be on a page.

    I tried modifying the default template (page.php), but outside of the loop, it can’t find the block data: calls to get_field('banner_image'); return nothing.

    Thank you.

  • I realized that I can get the post id in the header, but it still isn’t helping. get_field('banner_image', $id); isn’t working either.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.