How can I add Facebook SDK after
This topic contains 7 replies, has 2 voices, and was last updated by Paolo 10 years, 9 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
March 31, 2015 at 10:10 pm #35754
Hi there,
I want to add the Facebook SDK to my site just after the <body> tag. I am using Geo Framework Template and the latest version of WP Geo Directory and all plugins.Can you please help me with this?
<div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&appId=1378194292506778&version=v2.3"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script>March 31, 2015 at 11:12 pm #35765Hi,
please see: https://wpgeodirectory.com/support/topic/adding-a-button-to-listings/#post-35225
Thanks
April 1, 2015 at 12:15 am #35774Ok I am not 100% sure but I had a go using the following add action to my functions.php but get a syntax error in the first line.
So here is the code snippet you mentioned on that post, would you be able to show me an example of how I would include the facebook sdk into it?
add_action( 'geodir_details_main_content', 'facebook_sdk',35); function facebook_sdk(){echo 'hello world!';}Facebook Script
<div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&appId=1378194292506778&version=v2.3"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script>April 1, 2015 at 12:22 am #35775What syntax error?
this should work.
Maybe try a more personalized function name…
add_action( 'geodir_details_main_content', 'my_facebook_sdk',35); function my_facebook_sdk(){echo '<div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&appId=1378194292506778&version=v2.3"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script>';}Let us know,
thanks
April 1, 2015 at 12:24 am #35776I get
Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ in /home/media/public_html/pmg2015/wp-content/themes/GDF_child/functions.php on line 24I tried using a different function name (and the code snippet you posted) and got the same error.
April 1, 2015 at 12:38 am #35778ok, the best way to actually do this is to add the div facebook needs, via hook:
add_action( 'geodir_details_main_content', 'my_custom_action',35); function my_custom_action(){ echo '<div id="fb-root"></div>'; }Than add the script part in GD >> design >> scripts >> footer script
<script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&appId=1378194292506778&version=v2.3"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script>Let us know,
Thx
April 1, 2015 at 12:43 am #35779Perfect that works, thanks Paolo
April 1, 2015 at 2:26 pm #35810Glad we solved ! 🙂
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket