Support

Account

Home Forums Add-ons Options Page Header and Footer Scripts in Options

Solving

Header and Footer Scripts in Options

  • Hi,

    I’m new to ACF Pro, and I was wondering if there was a way to use the Options section to create textareas for header and footer scripts?

  • Do you mean to enter scripts to be added to the <head> and before the closing </body> of the site or page?

  • Exactly. Does this give me a way to do that?

  • Yes. You can create an options page for content to be added to the entire site. Set the formatting on the textarea field to no formatting and then in the header of footer include the content from the field.

    
      <?php the_field('my_code_field', 'options'); ?>
    </head>
    

    For individual pages/posts you’d do the same thing but, but you need to tell acf the right post ID

    
     <?php
       $queried_object = get_queried_object();
       if ($queried_object->ID) {
         the_field('my_code_field', $queried_object->ID);
       }
     ?>
    </head>
    
    • AndyiBM

    • October 9, 2018 at 8:55 pm

    Worth mentioning here that security plugins (such as WordFence) may throw up a warning screen when saving scripts to the Options page.

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

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.