Support

Account

Home Forums General Issues Add ACF field in

Solving

Add ACF field in

  • Using the suggested code inside of header.php:

    the_field('header_code', $post->ID);

    the code always outputs in the <body> section. I need it to be in the <head> section before the <body> as it will hold google analytics.

    I know that ACF needs help outside the loop so I used:

    global $wp_query;
    $post = $wp_query->post;
    the_field('header_code', $post->ID);

    yet it still does not output correctly. Can’t figure out what I’m doing wrong…

    Ideas?

  • Adding that I want to use ACF to output unique values for each page in the <head> and footer.

  • I’d want to utilize ACF to produce unique data in the head> and footer for each page.

  • Try

    
    $post_id = 0;
    $object = get_queried_object();
    if (is_a($object, 'WP_Post')) {
      $post_id = $object->ID;
    }
    the_field('header_code', $post_id);
    
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.