2

I use the following code to select specific image to be shown on FB sharing:

<link rel="image_src" href="<?php echo getTheField('an_image'); ?>"/>

The problem is, FB debugger tool can't see the image, and when I click "See exactly what our scraper sees for your URL" on Scraped URL on the debugger tool, this line is returned as:

<link rel="image_src" href="">

But, if I put only <?php echo getTheField('an_image'); ?> replacing the above mentioned line, it returns correct path of the image. So, it looks like the php command is fine, but Facebook scraper does not get it right. I don't see why, as normally, the server where the website is hosted should process the php code and return the variable, no matter who is making the request.

Any ideas?

5
  • Have you added any og tags? try adding <meta property="og:image" content="Your_Image_URL" />
    – Malcolm
    Apr 3, 2014 at 9:00
  • Yes, I also tried adding og tags in the header, but I can't get it to return correct values, as that must be in the header.php file, and the script plugin does not return values to that file. (I'm working with Getsimple CMS 3.3.1 and item manager plugin 1.6)
    – sashozs
    Apr 4, 2014 at 10:01
  • However, the problem is, if I type in a fixed URL at the place of "Your_Image_URL" (from your example), it works just fine. But, the script manages different products, and should display products corresponding image on FB share. When I generate the URL with php, FB doesn't scrap the generated URL (it's blank), but it's returned correctly if I output it on my page.
    – sashozs
    Apr 4, 2014 at 10:09
  • Something's wrong with your function. Are you sure you returned some text from function? Apr 15, 2014 at 20:41
  • Yes, actually the whole same page is generated by this exact function (Caption, short description of the product, price, image, text entered through a wysiwyg editor). So the complete page is properly shown, but through fb scrapper, nothing of this shows up :( Every field returned by getTheField is blank on the fb scrapped page view. And on the website everything appears just fine. You can see online by clicking any product on: topfriends.mk (at the moment I use fixed images and text for og so it won't show random "garbage" when shared).
    – sashozs
    Apr 22, 2014 at 11:11

1 Answer 1

0

This snippet might help you.

It works!

<?php 
function getTheField($something){
    return $something;
}
?>
<link rel="image_src" href="<?php echo getTheField('an_image'); ?>"/>

Output:

<link rel="image_src" href="an_image"/>
1
  • Where should I put it? I just tried putting it in the template file that shows the item, but it returns blank page now... :(
    – sashozs
    Apr 17, 2014 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.