Adding Conversion Tags to Multiple Pages in Body

Let me preface by saying I do not need to use INSERT HEADERS AND FOOTERS plugin. The INSERT HEADERS AND FOOTERS plugin adds tags site-wide. I do NOT need to add site-wide tags, I need to add my conversion tags to multiple specific pages.


I have a Linkedin conversion tag script that needs to be added into the body of several specific pages, so that I can track conversions on my site. I want to know how would I go about doing this. This is the code that I’ve put together and added to functions.php, but it keeps breaking the site.

add_action( 'wp_body', 'linkedin_leadconversion_insertion’);
function linkedin_leadconversion_insertion() { 
if (is_page(5163) || is_page(3098) || is_page(3353) || is_page(3308) || is_page(4777) || is_page(4891) || is_page(3158) 
|| is_page(3328) || is_page(3321)) { 
<script type="text/javascript">
_linkedin_data_partner_id = "114979";
</script><script type="text/javascript">
(function(){var s = document.getElementsByTagName("script")[0];
var b = document.createElement("script");
b.type = "text/javascript";b.async = true;
b.src = "https://snap.licdn.com/li.lms-analytics/insight.min.js";
s.parentNode.insertBefore(b, s);})();
</script>
<noscript>
<img height="1" width="1" style="display:none;" alt="" src="https://dc.ads.linkedin.com/collect/?pid=114979&fmt=gif" />
</noscript>
<?php }
add_action('wp_body', 'add_linkedin_leadconversion_insertion');

How would I be able to add this conversion code to multiple page’s body tags?

Hello @santosfel5,

Thanks for asking. :slight_smile:

Please update your code with the following:

function linkedin_leadconversion_insertion() {
    if (is_page(5163) || is_page(3098) || is_page(3353) || is_page(3308) || is_page(4777) || is_page(4891) || is_page(3158) 
|| is_page(3328) || is_page(3321)){
  ?>
    <script type="text/javascript">
_linkedin_data_partner_id = "114979";
</script><script type="text/javascript">
(function(){var s = document.getElementsByTagName("script")[0];
var b = document.createElement("script");
b.type = "text/javascript";b.async = true;
b.src = "https://snap.licdn.com/li.lms-analytics/insight.min.js";
s.parentNode.insertBefore(b, s);})();
</script>
<noscript>
<img height="1" width="1" style="display:none;" alt="" src="https://dc.ads.linkedin.com/collect/?pid=114979&fmt=gif" />
</noscript>

  <?php
}
}
add_action( 'wp_head', 'linkedin_leadconversion_insertion', 99999 );

Let us know how it goes.

Thanks.

This appears to be adding the script tags to the header of the specified pages. I need to add my conversion tags to the body of specified pages. How would I go about doing that?

Hi there,

X does have some actions and hooks which can be used for this case. I suggest that you change the code to:

function linkedin_leadconversion_insertion() {
    if (is_page(5163) || is_page(3098) || is_page(3353) || is_page(3308) || is_page(4777) || is_page(4891) || is_page(3158) 
|| is_page(3328) || is_page(3321)){
  ?>
    <script type="text/javascript">
_linkedin_data_partner_id = "114979";
</script><script type="text/javascript">
(function(){var s = document.getElementsByTagName("script")[0];
var b = document.createElement("script");
b.type = "text/javascript";b.async = true;
b.src = "https://snap.licdn.com/li.lms-analytics/insight.min.js";
s.parentNode.insertBefore(b, s);})();
</script>
<noscript>
<img height="1" width="1" style="display:none;" alt="" src="https://dc.ads.linkedin.com/collect/?pid=114979&fmt=gif" />
</noscript>

  <?php
}
}
add_action( 'x_before_site_end', 'linkedin_leadconversion_insertion', 99999 );

I used the x_before_site_end hook. You can see more stuff like that in this article:

https://theme.co/apex/forum/t/customizations-actions-and-filters-in-x/208

Thank you.

That worked! I’ve been working at this one for a few weeks. I’m so grateful for your help.

Glad that we could be of a help🙂

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