WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Put code into body tags near top, using a plugin (8 posts)

  1. derekbeck
    Member
    Posted 1 year ago #

    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>
  2. dmd54
    Member
    Posted 1 year ago #

    Can't you just stick it in your header?

  3. derekbeck
    Member
    Posted 1 year ago #

    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!

  4. dmd54
    Member
    Posted 1 year ago #

    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.

  5. dmd54
    Member
    Posted 1 year ago #

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

  6. derekbeck
    Member
    Posted 1 year ago #

    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.

  7. derekbeck
    Member
    Posted 1 year ago #

    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.

  8. derekbeck
    Member
    Posted 1 year ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic