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


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'); ?>

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

       $queried_object = get_queried_object();
       if ($queried_object->ID) {
         the_field('my_code_field', $queried_object->ID);
  • 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)

The topic ‘Header and Footer Scripts in Options’ is closed to new replies.