Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Jade Elizabeth - elokuu 21, 2014, 01:47:14 AP

Otsikko: Facebook image selection for links
Kirjoitti: Jade Elizabeth - elokuu 21, 2014, 01:47:14 AP
When I link to my site it shows me one picture I can link up as the picture for the link, and that picture is always in the footer.

Is there a way I can get FB to recognize avatars and pictures inside the post?
Otsikko: Re: Facebook image selection for links
Kirjoitti: Biology Forums - elokuu 21, 2014, 01:55:25 AP
Curious about this too...
Otsikko: Re: Facebook image selection for links
Kirjoitti: Jade Elizabeth - elokuu 21, 2014, 02:16:31 AP
You're having the same issues as me? I've been saving the picture and using the "upload picture" option but it's a pain in the butt!
Otsikko: Re: Facebook image selection for links
Kirjoitti: Biology Forums - elokuu 21, 2014, 12:26:28 IP
Yea, of course, or it finds 4 random images on that page and it's hit-or-miss if one of them is the one I'm interested in.

There has to be some sort of marking on the <img that FB looks for.
Otsikko: Re: Facebook image selection for links
Kirjoitti: Suki - elokuu 21, 2014, 12:53:25 IP
There is if you use facebook "Open Graph" https://developers.facebook.com/docs/web/share

You need to add lots of stuff to your pages: https://developers.facebook.com/docs/web/webmasters

and its really difficult to get it done right for forum topics.

I remember there was a mod here that implemented the open graph stuff, it probably don't work properly by now but you can use it as reference to know just how many changes are needed to make it work on a forum's topic.

Additionally, if you follow all their suggtestions, theres still the chance it won't work properly anyway,  due to how facebook crwals your site using their own bots, it spossible that facebook will mark all your topics as one single unique page and thus it will use the very first image that was crawled from your site.
Otsikko: Re: Facebook image selection for links
Kirjoitti: Biology Forums - elokuu 21, 2014, 01:11:46 IP
That does look intense.
Otsikko: Re: Facebook image selection for links
Kirjoitti: Jade Elizabeth - elokuu 21, 2014, 08:43:10 IP
Is there a way to make it use the site logo or something then? That would be better. maybe we can make it a hidden value or something. It seems like a lot of bull crap for us to go through to make our sites work with theirs - they should be doing that not us!!
Otsikko: Re: Facebook image selection for links
Kirjoitti: Biology Forums - elokuu 21, 2014, 10:22:25 IP
Here's what I've done. Pretty much it rotates randomly between three images of my choosing. I put this in the header section inside index.template.php.


// Set meta tags...

$bio_icon = '<meta property="og:image" content="'.$settings['default_theme_url'].'/images/biology.png" />';
$bchem_icon = '<meta property="og:image" content="'.$settings['default_theme_url'].'/images/biochemistry.png" />';
$other_icon = '<meta property="og:image" content="'.$settings['default_theme_url'].'/images/others.png" />';

// Put into an array...

$values = array($bio_icon, $bchem_icon, $other_icon);

// Randomize

$FB_image_tag = $values[array_rand($values)];

// Publish

echo'<!--Facebook-related tags-->',$FB_image_tag,'';


Let me know if you need help incorporating that.
Otsikko: Re: Facebook image selection for links
Kirjoitti: Jade Elizabeth - elokuu 21, 2014, 10:25:16 IP
Hey that is awesome! Thank you!!
Otsikko: Re: Facebook image selection for links
Kirjoitti: Biology Forums - elokuu 21, 2014, 10:28:09 IP
Hope it works.