How can I add code to footer?

Hi there,

I’m trying to set up my Amazon Associates accounts and, as part of the OneLink tool, I have to copy the JavaScript code below and integrate it into the footer/before the end tag of the body of my website:

<script src="etc."></script>

Do you know how I can achieve this, given that I have a child theme installed?

Thank you,
EW

Hey EW,

There are two ways you can add HTML before the end body tag.

1.) You can add action to the footer like the code below. That should be added in your child theme’s functions.php by the way. Be careful with this though as syntax error could break your site and this is outside the scope of our support.

add_action( 'wp_footer', 'add_footer_code', 9999 );

function add_footer_code()  { ?>
  <script src="etc."></script>
<?php }

2.) Use a third party plugin like Insert Headers and Footers. This is a safer route because you don’t need to work inside functions.php. Please see this article for usage instructions.

Thanks.

Thank you, Christian!

We are delighted to assist you with this.

Cheers!

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