Adding Facebook like box

Hi. I would like to add the Facebook like box to my site, which uses a Genesis theme called Metro Pro. Facebook wants me to enter the following JavaScript SDK in the header.php file. However, Genesis tells me not to mess with that file. Where/how can I add this code so that I can use embed the Facebook like box?

<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_US/sdk.js#xfbml=1&version=v2.7&appId=234373793297811";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

  • Nithin

    Hi Bill,

    Hope you are doing good today. :slight_smile:

    The above code should be added ideally right after the <body> tag, could you please add the following code in your child themes functions.php file, and check whether it works:

    function fb_add_like_box() {
    	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_US/sdk.js#xfbml=1&version=v2.7&appId=234373793297811';
    			fjs.parentNode.insertBefore(js, fjs);
    		}(document, 'script', 'facebook-jssdk'));
    		</script>";
    }
    
    add_action( 'genesis_before', 'fb_add_like_box' );

    This should add the above code inside your <body> tag, please let us know if you still need any further assistance. Have a nice day. :slight_smile:

    Kind Regards,
    Nithin