1
votes

This is the url that I want the user to be able to share: http://dealsfortherich.com/product/6379316

So my application (PHP) constructs this URL:

https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2F6379316

If you check out that link, you will see that the product number has been truncated. Sharer.php is ignoring the number after the slash (%2F) If I make that number alpha-number, it works:

https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2F6379316X

or https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2FX6379316 or https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2F637X9316

Adding the trailing slash doesn't help: https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2F6379316%2F

Obviously, I can write a condition in my application to handle a url like: http://dealsfortherich.com/product/6379316X But then I have duplicated content as far as search engines are concerned.

Should I just give up and do it without using sharer.php?

1
BTW, I'm using PHP to generate this link server-side instead of using developers.facebook.com/docs/reference/plugins/like because having the user's browser build about 20 of these buttons in javascript causes a huge responsiveness issue (lag).daSong
How about a trailing slash and page? /index.htmarttronics
thanks, that's a good try... but my application doesn't respond well to: dealsfortherich.com/product/6379316/index.htmdaSong
the hashtag works on my page no problem... but sharer.php seems to still be truncating the number before the hashtag! facebook.com/sharer/… and again, sharer picks it up if it is alphanumberic: facebook.com/sharer/…daSong
I'm not familiar with the correct syntax to use with sharer.php, but can you wrap the url in quotes 'likeThis' ?arttronics

1 Answers

0
votes

Figured it out! The problem was that facebook was not scraping the page: http://dealsfortherich.com/product/6379316

The facebook object debugger was showing that the scraper was seeing a canonical name of: http://dealsfortherich.com/product/

This was happening even though I issued:

remove_action('wp_head', 'rel_canonical'); 

before calling wordpress' get_header() (which in turn calls wp_head()), which should have been removing the wrong canonical link.

The problem was that the filter fb_meta_tags (from a plug-in) was adding a bunch of OG tags before the OG tags that I thought I was setting! Sure enough, one of the tags beting set was:

<meta property="http://ogp.me/ns#url" content="http://dealsfortherich.com/product/" />

This is how I solved it, in my php, before get_header() is called:

add_filter( 'fb_meta_tags', 'remove_og_tags' );
function remove_og_tags( $meta_tags )
{
  $meta_tags['http://ogp.me/ns/fb#app_id'] = null;
  $meta_tags['http://ogp.me/ns#type'] = null;
  $meta_tags['http://ogp.me/ns#title'] = null;
  $meta_tags['http://ogp.me/ns#image'] = null;
  $meta_tags['http://ogp.me/ns#description'] = null;
  $meta_tags['http://ogp.me/ns#url'] = null;
  return $meta_tags;
}

That prevented the wrong OG tags from getting added before I added mine:

<link rel="canonical" href="<?php echo $page_path; ?>"/>
<meta property="fb:app_id" content="xxxxxxxxxxxxx" /> 
<meta property="og:type" content="product" /> 
<meta property="og:title" content="<?php echo $the_title; ?>" /> 
<meta property="og:image" content="<?php echo $image_url; ?>" /> 
<meta property="og:description" content="<?php echo $tweet_text.$the_title; ?>" /> 
<meta property="http://ogp.me/ns#url" content="<?php echo $page_path; ?>"  />

Everything is now working beautifully.