WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I use a plugin to put this inside the body of every page on my WP site, for facebook integration. (Yes, I know other plugins can do it, but I want to do it myself.) Facebook recommends as close to the top of the lead body tag as possible.


<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/all.js#xfbml=1&appId=99999999999";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
share|improve this question
Giving a -1 without feedback is useless... – Derek W Beck Sep 25 '12 at 23:56
Huh? Why would you down-vote your own question? – Brian Fegter Sep 26 '12 at 0:14
no, someone else downvoted it without any explanation or comment (unless I did it inadvertently) – Derek W Beck Sep 26 '12 at 7:40

Put that script into a file somewhere in your theme folder. Include it using the following code in your theme's functions.php file:

function wpa_65602_enqueue_scripts() {
     wp_enqueue_script( 'facebook', get_bloginfo( 'template_url' ) . '/path/to/script.js' );
add_action( 'wp_enqueue_scripts', 'wpa_65602_enqueue_scripts' );
share|improve this answer
instead of template_url, how can I just call to the plugins directory? do I need plugins_url ? – Derek W Beck Sep 19 '12 at 20:42
Yes, use plugins_url. – Joseph Leedy Sep 19 '12 at 23:49
How would the wp_enqueue_script line appear if the file is script.js and is in my plugins directory in plugin folder "1775"? – Derek W Beck Sep 20 '12 at 3:13
up vote 0 down vote accepted

Ultimately, further research found there is an effort to add wp_body as a hook, but it is not yet implemented. In the meantime, one can append or prepend it to the content of the loop. But in this case, adding the facebook stuff at hook wp_footer works. This is what I've done.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.