Hasan Can Saral
Hasan Can Saral

Reputation: 3288

Facebook Share Button data-href Wordpress Permalink Displays: "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?

Upvotes: 0

Views: 1996

Answers (2)

Hasan Can Saral
Hasan Can Saral

Reputation: 3288

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.

Upvotes: 0

dustincaruso
dustincaruso

Reputation: 109

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>

Upvotes: 1

Related Questions