
I run this site using WordPress, but a lot of the other sites I develop are created with Joomla.
Recently, I had a lot of trouble getting the thumbnail and meta-description from my sites to show up when I tried to share them on Facebook. Only the site name and the link to the article would be showing when I tried it. Turns out this was a Facebook bug but it really made me dive into the whole process.
If you’re not familiar with Facebook you might be wondering why this is so important. Let’s take a look.
When I see an article I like and want to share with my friends, if they have a share button available, I’ll use that, or if necessary I’ll copy the link and paste it in using the link button in the Facebook status field.
So let’s check out one of my favorite sites, gossip site mediatakeout.com. When I see a funny article there, of which there are many, I’ll click on their big-azz Facebook share button they use (not sure why that thing is so dang big).
Here’s what I get when I do that:
Essentially nothing. So when that posts to my wall, that’s all my friends are going to see. There’s no description or thumbnail with this post. It’s pretty boring and people are much less likely to click on the link if they can’t even see what it’s about. I know I usually pass over boring links like this.
So to show a site that does this correctly, let’s look at a link from this very site. When I browse to one of my articles and click the share button, I get this:
Now this looks a lot more interesting. There’s a description of the article, and even a thumbnail. Now that link is a lot more likely to be clicked than the generic one above it.
So again, this is WordPress, how do we get this in Joomla? Well, honestly, sometimes it just works, and other times it doesn’t seem to. I ended up checking out Facebook’s specs on sharing here:
http://wiki.developers.facebook.com/index.php/Facebook_Share/Specifying_Meta_Tags
And it turns out there’s three basic items that should be present on the page you want to share.
- Meta Title
- Meta Description
- Image thumbnail source
That last one is the tricky one!
In Joomla, it’s trivially easy to put in the meta description in the ‘Metadata Information’ tab at the bottom right of the Parameters sidebar in your article entry screen.
The title I’ve never had a problem picking up in Facebook from the page title. Normally, Joomla SEO extensions like SH404SEF or Artio JoomSEF can help you with all the metadata, anyway.
But that thumbnail. It’s not a meta tag, it’s a ‘link’ tag. Not so easy to get into the head of your Joomla document.
I spent some time wrangling with it and I came up with a workaround that didn’t involve hacking the core header file.
Essentially we use a bit of php to fill in the name of your image, based on which page you’re on. We do this using the Menu ID assigned to your article. You can find this ID by going to the Menu that your article is assigned to. See this example:

The red part is the ID number we need. We’ll add this number onto the end of our link tag so it pulls the correct image based on which page we’re on.
So now on to the PHP. Joomla has a variable which allows it to get the Menu ID of an item. It’s called, appropriately enough, ‘$itemid’.
So what we’ll do first is open up your template index.php file (it should be found by going to your ftp Home>templates>YOUR_TEMPLATE>index.php.
Or if you’re editing through the Joomla backend, go to Extensions>Template Manager, then click your template,and finally click the ‘Edit HTML’ button. You’ll get a screen with the code of your index.html where you can now edit.
So the first thing we need to do to get started using $itemid is to declare, or initialize the variable (I’m not a true php guru so this may not be the proper term).
To do this we’ll use this code:
<?php $itemid = JRequest::getVar(‘Itemid’); ?>
You have to place this before we actually try to use the $itemid variable. So I put this directly after my first head tag.
Then it’s time to put in the link tag that Facebook will be looking for. The code I use is as such:
<link rel="img_src" href="http://www.example.com/images/stories/fbthumbs/thumbnail<?php echo $itemid; ?>.jpg" />
I put this tag right after the Joomla ‘head calling’ tag that looks like this:
<jdoc:include type="head" />
Check this pic for an example (click for larger view):
So to break this down, Facebook is going to prefer whichever image is called in this link. Reading the specs from the Facebook link I provided above says that your link has to be an absolute link.
You can see that I have an absolute link there, then I used my ‘images/stories’ folder and created a new folder in there called ‘fbthumbs’, but you can use whatever directory is convenient for you.
Following that as the link continues, you see it says ‘thumbnail’ and then our php code sandwiched right up against it. What’s happening here is that every image I put in this directory will be named ‘thumbnail’ with a Menu ID tacked right on the end. So if my Menu ID was ’44′ as in the image above, my image would be named ‘thumbnail44.jpg’.
The php code is set to “echo” the item ID of whatever page we’re on, so it replaces the php with the item ID, then we wrap it up by adding the ‘.jpg’ on the end and close the tag.
So whenever you make an article, you’ll need to check the Menu ID for it, then name your photo ‘whatever’ and append that Menu ID onto it. As long as it goes into the right directory, Facebook should have no problem finding your preferred thumbnail to use when someone tries to share the item.
And that should do it!
Now, with all that said, this is a workaround, and I hate workarounds. I’d love it if someone came up with a simple extension to handle this.
On my site True Tales of the Soryan Order I use a module called Flexheader 3.
This extension allows you to have a different header for every page based on the Menu ID. It would be great if someone could adapt this header or point out one that does something similar, only for our specific Facebook situation.
Anyway, that’s all for now and please contact me or leave a comment if you know of a simpler solutions. Peace!
UPDATE: I only thought of this later, but I should mention that some people have reported that having any EXIF metadata in your image may cause Facebook to not show your thumbnail. I haven’t observed this behavior myself, but plenty of others have. Here’s one of many threads that discusses how to remove this: http://photo.net/digital-darkroom-forum/00Dy2C.


























any tips for making it work in WordPress ( selfhosted godaddy)
it seems to have stopped working last week sometime ,
Many thanks for your helping out !
Hey Brian, as far as I knew Facebook got it working again. Check this thread:
http://forum.developers.facebook.com/viewtopic.php?id=60344&p=1
on the Facebook developer forum, where they admit it was their mistake.
Is Facebook getting ANY of the metadata? Or is it just the thumbnail not showing?
On one of my Joomla sites, it was pulling the thumbnail from an image that had been on my front page two days prior. It may be that Facebook needs to still work through clearing it’s own cache or something. Especially if that page has been shared before.
It’s tough to nail down FB since they keep changing stuff daily…
Hey there !
Thanks for getting back to me , Facebook isnt getting any of the data and looks like it does in the first image above **” heres what i get when i do that ” . It has been like this for over a week .Its very aggravating , i filed a ticket but who knews if they will ever get to it .
Any info would really be appreciated if you hear anything
Thanks !
brianbrianbrian@aol.com
I am having a hard time with this… Facebook will alternate between posting my Meta Description and it wont post the picture on Facebook at all I have labeled the end of my jpg to my Main Articles ID as well as made another one with the menu ID I am really having a hard time here but feel like i am doing it just as you posted and have tried even changing my picture to a more simple one which i wouldnt think i would have to since I have seen Bigger/More Colorful pics on Facebook Links… Any help would be great! Thanks for this Article BTW !
Hi Phil,
I noticed my article was missing a crucial picture in it (gotta maintain these old posts, folks!), so that might have gummed up the works.
I’ll email you my index.php file from one of my Joomla sites tonight so you can see exactly how I have it set up. You probably have it right.
One thing I noticed with the Facebook share.php setup. It seems to cache this stuff for a long time. I have no hard evidence of this, but it seems like if there is a bug or hiccup at Facebook, and then you submit your article and the thumbnail/description does not appear, then you kind of have to wait it out until the cache refreshes, it will always be screwed up until it does that.
Like I said I have zero hard evidence of that but it’s kind of suspicious…
yeah my site just crashed
its giving me a
Database Error: Unable to connect to the database:Could not connect to MySQL
message any ideas?
That sounds like a webhost error. You can try contacting your webhost to see if they’re experiencing issues. There’s also a long thread on that very error over on the official Joomla forums here:
http://forum.joomla.org/viewtopic.php?f=431&t=198257
ok so its prob not my fault
hew: I have a ton of hours on this LOL
Thank you very much for all of this information you help me out lots as my knowledge of web coding is old and most of this is new to me