Add global code after <body>-tag

How can I add this code after the body opening tag?

The code i need to add:

<script 
  async 
  src="https://eu-library.klarnaservices.com/lib.js"
  data-client-id="ID"
></script>

Official installation guide:
“Add the following code to your website after the < body > tag. We recommend adding the code to all pages of your website. The code only needs to be inserted once per page. Note: It is possible to load the code via a tag manager, but we do not recommend this as this increases the loading times for visual elements”

Thanks in advance
Steven

Hey Steven,

Please install and activate the child theme and login through FTP then edit the functions.php of the child theme then add this code:

// Add code after body tag in X/Pro themes

add_action('x_after_body_begin', 'custom_code_after_open_body');

function custom_code_after_open_body() {
  ?>
      <script 
      async 
      src="https://eu-library.klarnaservices.com/lib.js"
      data-client-id="ID"></script>
  <?php
}

Hope this helps.

Thank you. It works :slight_smile:

You’re most welcome, Steven. :slight_smile:

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