- This topic has 7 replies, 2 voices, and was last updated 3 years, 9 months ago by David.
-
AuthorPosts
-
July 13, 2020 at 1:23 am #1361594sjoerd89
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
July 13, 2020 at 3:12 am #1361680DavidStaffCustomer SupportHi 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.July 13, 2020 at 3:19 am #1361692sjoerd89And 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
July 13, 2020 at 3:34 am #1361706DavidStaffCustomer SupportYou should see a tab called Display Rules:
https://docs.generatepress.com/article/hooks-element-overview/#display-rules
In Location, you can select Posts, then a second field aside that will display which you leave set to All Posts.
July 13, 2020 at 4:17 am #1361756sjoerd89-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 π
July 13, 2020 at 4:21 am #1361762DavidStaffCustomer SupportIn Appearance > Elements – at the top of the screen you will see Legacy Hooks. You should find you your old codes in there.
July 13, 2020 at 4:25 am #1361767sjoerd89In 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!
July 13, 2020 at 4:48 am #1361795DavidStaffCustomer SupportYou’re welcome
-
AuthorPosts
- You must be logged in to reply to this topic.