Home Forums ACF PRO Add ACF Field in WP_HEAD


Add ACF Field in WP_HEAD

  • Hi,

    I like to add a ACF to my Posts where I can add a SCRIPT from GetYourGuide to the HEAD if necessary.

    For this I have created a new ACF field “get_your_guide_script” with the rule “all posts”

    Then I have added the following code to my functions.php

    /* Add GetYourGuide Script to HEAD */
    function acf_header_script() {
      $schema = get_field('get_your_guide_script');
      echo get_field('get_your_guide_script');
    add_action ( 'wp_head', 'acf_header_script' );

    I don´t know if this is the correct way – but i works 🙂

    Now it happens in posts that I want to leave the GetYourGuide field empty, because I don’t want to include GetYourGuide in the post. Then the code in the function.php makes no sense.

    Is it possible to extend the code above with a query like:
    If get_your_guide_script in a post = empty, then include nothing in HEAD?

  • You code should output nothing if the field is empty.

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

You must be logged in to reply to this topic.