How do you add HTML to a single page after the <head> tag of a page built with Cornerstone

HI there,

I’m trying to set up an experiment to A/B test two landing pages with Google Optimize. I need to add code right after the tag on a single page, but that page was built with Cornerstone, and I can’t find the HEAD tag anywhere.

I have already tried adding the code to a CONTENT and a RAW HTML element at the top of the page, but Optimize needs it right after the tag to be able to find it.

How can I add this code to the page?

Many thanks,

1 Like

Hey Lisa,

Thanks for writing in! There is nowhere you can add a custom code into a specific page in the theme right now. You can do it by adding a custom code function in your child theme’s functions.php file instead. Because what you are trying to accomplish requires a template customization, we would highly to suggest that you use a child theme. This allows you to make code changes that won’t be overwritten when an X update is released.

_Tip: After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

After the child theme is set up, please add the following code in your child theme’s functions.php file

function add_custom_code(){ ?>
  <?php if ( is_page('123') || is_page('456') ) : ?>

  	<!-- // insert the code start here -->

  	<!-- the code probably here  -->

  	<!-- // insert the code ends here -->

  <?php endif; ?>
add_action('wp_head', 'add_custom_code');

In the code above, 123 and 456 are the page ID so that the code will only take effect in these page. To get the actual page ID in your pages, please check this out:

Hope this helps. Please let us know how it goes.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.