dongtuoao7987
2014-11-11 12:21 阅读 360

Facebook分享按钮数据-href Wordpress永久链接显示:“facebook.com/v2.0 ...”

This is how I render my button:

function fb_share() {
    $permalink = get_permalink();
    echo '<div class="fb-share-button" data-href="'.$permalink.'" data-layout="button_count"></div>';
}

I include the scripts right after tag opens. However, what it does when you click share is:

Facebook screenshot

Any thoughts?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    dqcd84732 dqcd84732 2014-11-16 20:34

    The problem arises because I have been testing my theme using MAMP and having the string "localhost" in the browser URL. As @dustincaruso mentioned:

    <div class="fb-share-button" data-href="<?php the_permalink(); ?>" data-layout="button_count"></div>
    

    works perfectly. Thanks.

    点赞 评论 复制链接分享
  • douzhicong5965 douzhicong5965 2014-11-11 12:33

    Try this code directly in the PHP/HTML markup of your theme. It will create a link to the current page/URL in the "data-href" attribute.

    <div class="fb-share-button" data-href="<?php the_permalink(); ?>" data-layout="button_count"></div>
    
    点赞 评论 复制链接分享

相关推荐