Site logo

Archived topic

Adding a function in functions.php

7 replies · Started by sjoerd89 on July 13, 2020

Viewing posts 1–8 of 8

Hi everyone,

i am trying to get a function to work on my website. At the moment i use it in functions.php of my child theme. The code i use is

function wpb_linkedin_share_after($content) { 
$sharecode .= '<script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>
<script type="IN/Share" data-counter="top"></script>'; 
$newcontent = $content . $sharecode; 
return $newcontent; 
} 
add_filter('the_content', 'wpb_linkedin_share_after');

This function makes a linkedin share button but currently shows up on every page of my website.
I would like to only show this on post pages.

Is it better to use this in GP-hooks? because there i also do not see the option for post pages.
Thanks for reading :)

Sjoerd

Hi there,

try this:

function wpb_linkedin_share_after($content) { 
  if ( is_single() ) {
    $sharecode .= '<script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>
    <script type="IN/Share" data-counter="top"></script>'; 
    $content .= $sharecode; 
  }
  
  return $content; 
} 
add_filter('the_content', 'wpb_linkedin_share_after');

If you wanted to add it after the content you could do it with a Hook element.
You only need this for the hook content:

<script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>
<script type="IN/Share" data-counter="top"></script>

And you would select the after_content hook and use the Posts > All Posts display rule.

And you would select the after_content hook and use the Posts > All Posts display rule.

This part is a bit confusing to me sorry.

I only see execute PHP and disable Hook as options

-edit- found the other hooks under legacy hooks now, thanks for your help!!

I had elements turned off on my website so i never saw this option.
The code that i had in Hooks is now gone tho?
I do not see the hooks part anywhere anymore now.

I got the other part working now :)

In Appearance > Elements - at the top of the screen you will see Legacy Hooks. You should find you your old codes in there.

In Appearance > Elements – at the top of the screen you will see Legacy Hooks. You should find you your old codes in there.

thanks a lot for your help!

You're welcome

This archived topic is closed to new replies.