napionder
napionder

Reputation: 1

Facebook comments won't accept get permalink

I have manually installed facebook comments on my wordpress blog, but keep getting an error message below the commentbox:

Warning: http://invalid.invalid/?php%20echo%20get_permalink();%20?> is unreachable.

I put this in my header:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml">

and :

<meta property="og:title" content="<?php echo get_the_title(); ?> "/>
<meta property="og:url" content="<?php echo get_permalink(); ?>"/>
<meta property="og:image" content="xxxxxxxxx"/>
<meta property="og:description" content="<?php
    while(have_posts()):the_post();
    $out_excerpt = str_replace(array("\r\n", "\r", "\n"), "", get_the_excerpt());
    echo apply_filters('the_excerpt_rss', $out_excerpt);
    endwhile;   ?>"/>
<meta property="fb:app_id" content="xxxxx">
<meta property="fb:admins" content="xxxxx"/>

in my single.php file I added this:

 <?php if (in_category('randomposts')) {
     echo '<div></div>';
} else {
 echo '<div class="fb-comments" data-href="<?php echo get_permalink(); ?>" data-num-posts="5" data-width="640"></div>';
}

?>

I checked my site in the facebook debugger/linter and no problems show up there. The comment box is displayed on my page, but that warning is bugging me. You are able to share to facebook, but then it shows http://invalid.invalid as url. I figured out that the problem is the 'echo get_permalink' in my single.php file. When i enter my homepage url instead, there is no warning and everything functions as it should, except that it shares my homepage url and not the post url.

Here is an example:

http://www.itrainmymind.com/this-is-a-tespost/

Upvotes: 0

Views: 1940

Answers (2)

Lucius SmashTech
Lucius SmashTech

Reputation: 1

with facebook, you have to use this for hyperlink in wordpress single.php page

<?php $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; echo $url;?>

Just using the default code

<?php echo get_permalink(); ?>

will NOT work

Upvotes: 0

scibuff
scibuff

Reputation: 13755

You have two echo's there. What you want is

echo '<div class="fb-comments" data-href="', get_permalink() ,'" data-num-posts="5" data-width="640"></div>';

Upvotes: 2

Related Questions