WordPress.org

Ready to get started?Download WordPress

Forums

Facebook share button pulling wrong post (2 posts)

  1. gmorehoudh
    Member
    Posted 5 years ago #

    I've been trying to implement a Facebook share button (among others) on the header of every post on the home page. I've used the code specified on Facebook's own site, and am feeding it the permalink for the post and the post title. I've viewed the source of the page and verified that these are correct.

    I'm also doing this in the header on single post pages.

    When I click the button on a single post, it works fine. However, when I click the button on a post on the index, Facebook inevitably pulls the wrong post into its share popup. I am not sure what is going on -- I've added a meta title tag to the single post pages as Facebook suggests but it's not helping. I think it's never even loading the right page, and somehow attempting to share a post somewhere on the index page, but always the wrong one. I'm not sure how it would even detect to load the index page instead of the URL I feed it, since the fbs_click javascript isn't that complicated:

    <!-- facebook -->
    <script>
    function fbs_click() {
      u='<?= the_permalink() ?>';
      t='<?= trim(htmlspecialchars(the_title())) ?>';
      window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
      return false;
    }
    </script>
    <a href="http://www.facebook.com/share.php?u=<?= urlencode(the_permalink()) ?>" onclick="return fbs_click()" target="_blank"><img class="iconistan-icon" src="http://images.mydomain.com/common/bookmarking/facebook.png" alt="Facebook" /></a>

    My only guess would be that Facebook is detecting the HTTP referrer and trying to pull data from that, and just ignoring what I give it for some reason.

  2. gmorehoudh
    Member
    Posted 5 years ago #

    Oh, and FYI, I'd prefer not to use ShareThis for this if possible. I'm trying to do something pretty custom.

Topic Closed

This topic has been closed to new replies.

About this Topic