Support » Fixing WordPress » Put code into body tags near top, using a plugin

  • Resolved derekbeck

    (@derekbeck)


    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.

    Thanks!

    <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>
Viewing 7 replies - 1 through 7 (of 7 total)
  • Can’t you just stick it in your header?

    Maybe, and it’s worth a try if nothing else (good point!), but I’d like to put it in the body anyhow, if only to learn how. Thanks!

    You could also put it in the footer, that would include it within the body tags but of course not be at the top of the page.

    …but it should go and work in the header, right after your <body> tag.

    No problem, the more ideas the better. And it turns out, no, it cannot be in the header. It gives an error for facebook. It must be in the body.

    I think the footer might be the best way if no other ideas crop up. I’m going to try to figure out how Simple Facebook connect plugin does it.

    Footer is the best option, and works in this case. For the future, there is an effort to create a wp_body hook, but it does not yet exist.

    Thanks for your help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Put code into body tags near top, using a plugin’ is closed to new replies.