Kinetic Pulse
  • Home
  • Services
  • Portfolio
  • Blog
  • Terms
  • Contact

How to get correct Zen Cart product thumbnail when posting to Facebook [Updated: 26th Aug 13]

November 8, 2011

When users post a link to your products on Facebook, its nice for the automatic link to show a picture of an actual product.

Unfortunately Zen Cart doesn’t have this facility out of the box, but its not too tricky to add it yourself.

In your template’s html_header.php add the following lines for all the Facebook Open Graph tags:





" />

/includes/templates/YOU_TEMPLATE/images/logo.png"  />

/images/" />




  




Note: this is using a new DEFINE variable called META_TAG_PRODUCT_IMAGE.

This needs to be defined in your modules/meta_tags.php file.

(use an override for your template obviously by copying the existing one into a folder called YOUR_TEMPLATE. Also check what the default directory for your product images is – this code is assuming they are directly beneath the images folder. You’ll need to do extra work to figure ou if they are in more complex subdirectories)

In the line around 194 that is building the SQL to pull data from the products table add the following  field to the list:

p.products_image

Then around line 208 below where it says // custom meta tags per product  add the following line:

$meta_products_image = $product_info_metatags->fields['products_image'] ;
define('META_TAG_PRODUCT_IMAGE', $meta_products_image);
 

(Note: I have moved both lines together as it seemed to make it work on ZenCart 1.5. It looks like there were more if statements added in this version!)

Thats it. You can see it in work here http://www.thepartypirate.com and in version 1.5 http://www.framecraftonline.com

 

Share

Facebook Google+ Twitter Pinterest Email
  1. TJ says

    January 8, 2013 at 12:43 am

    I couldnt get it to work 🙁 Followed exactly just not sure why images will not show up on facebook. Very annoying.

  2. TJ says

    January 8, 2013 at 1:12 am

    My images are in their own directory under images for each product category. This helps with SEO, but is a pin with facebook. How would I change that so they appear?

  3. TJ says

    January 8, 2013 at 1:18 am

    <meta property="og:image" content="http:///images/MyDirectory/” />

    Obviously I need the MyDirectory automatically pulled using this line, but I simply do not know how to do it.

  4. TJ says

    January 9, 2013 at 2:12 am

    Hi thanks for deleting my comments. I really did need some help.

  5. Laura James says

    January 9, 2013 at 9:31 am

    Hi TJ, Sorry if you thought I had deleted your comments – they were still waiting approval and I hadn’t had time to read them.

    My first suggestion would be to change the php shortcode <? = in front of ‘$_SERVER[“SERVER_NAME”]’ to <? echo (that was in the code above – I’ve edited now so that all the echos are explicit and not using =)

    (Maybe your PHP installation doesn’t like those? In know in some later versions of PHP you have to turn that shortcode on explicitly)

    Then check you have hardcoded the image folder name correctly in the ‘meta property=”og:image” ‘ line to whatever your image folder is,

    HTH

  6. Ethan Lee says

    May 18, 2013 at 5:04 am

    Thanks a lot! Works like a charm. Was about to slowly look for each parameter to insert into the Meta information but your code saved me loads of time.

  7. Rob Morrish says

    July 17, 2013 at 9:28 am

    Hi Laura, Thanks for this code, I have been trying to sort this for a while now! Something broke and stopped the thumbnails from working but while your code sorts the og parameters for everything I’m still getting an error on the image from facebook debugger saying it too small. Do you have any idea what this could be? Thanks, Rob

  8. Laura James says

    July 17, 2013 at 10:23 am

    Hi Rob,
    Have you taken a look at the FB image guidelines: https://developers.facebook.com/docs/opengraph/howtos/maximizing-distribution-media-content/#tags
    The image needs to be at least 200px by 200px (although I’m sure I’ve had it work with smaller images) It took a look at your site (v nice btw!) but couldn’t see an image in the property=”og:image” – just the path? I guess you might still be working on it though…

  9. Rob Morrish says

    July 17, 2013 at 10:37 am

    Thanks for the link ill have a go through but i think the images are alright, it just seem to be falling short on getting the

    images/” />

    bit of the head to propagate. not sure if its something ive changed when editing the site but the FBdebugger seems to show the og:image link stopping at images/ , so does the source on the site, not surprised its too small then!

    im just trying to track back through the php to find where a break may be. no luck yet though

  10. Rob Morrish says

    July 17, 2013 at 12:47 pm

    Sorry Laura, can I pick your brain? I cant seem to get the META_TAG_PRODUCT_IMAGE variable working. I can see in the DB all is well and the lines of code make sense, it just doesn’t want to fulfil the link. Any Ideas?

  11. Laura James says

    July 17, 2013 at 1:47 pm

    In the meta_tags.php file are you *sure* you’ve:
    1) Added this field “p.products_image” to the SQL statement to pull it from the DB in the query?

    2) Created the $meta_products_image variable to store this value?

    3) Added the define statement define(‘META_TAG_PRODUCT_IMAGE’, $meta_products_image);

    (TBH I honest I did this for Zen Cart 1.3.8 I think so the db field name may have changed in 1.5 maybe – but the rest should still work…?)

    Let me know how you get on :>

  12. Brian says

    August 26, 2013 at 5:34 am

    Laura,

    I love this code, but I cannot get it to pull the product_image info out of the database and put it into the META_TAG_PRODUCT_IMAGE..I’m using Zen 1.5.. The rest of the code is working properly. I am testing it using Facebooks debugger. Any suggestions?

    Brian

  13. Brian says

    August 26, 2013 at 6:43 am

    An update to that previous post.. it’s pulling the correct information into the variable.. it just cannot put it into this string properly.

    <meta property="og:image"
    content="http:///images/” />

    Must be a format issue with PHP or Zen Cart 1.5…

  14. Laura James says

    August 26, 2013 at 4:52 pm

    HI Brian,
    I’ve checked the code on 1.5 and it sort of works – I’ve had to move both the lines together in the meta_tags.php, but I’ve updated the code in the post to reflect this.

    I’ve also expanded the bit that adds all the FB OG tags in the html_header.php

    So maybe you could try that? And also trying changing the short code “=” for “echo” as maybe your install of PHP doesn’t support that?
    (I’ll go change that in my post too – as someone else looked like they had a problem with that too!)

    Good luck

    Laura

  15. Brian says

    August 26, 2013 at 5:49 pm

    Alright.. I have it working on my side, but when using Facebook debugger, so some reason, it’s not updating the og tags with product info…

    Page source shows that it’s correct.. kind of an odd deal. It looks like Facebook is pulling a bad page and just getting the home page..

    i.e. http://www.bennettauctionsales.com/-c-14750/-p-144784.html

    Thanks for the help though!

  16. Brian says

    August 29, 2013 at 12:08 am

    SOLVED!

    I had to allow Private Spider sessions to use cookies.. I am using an Auction Module that is using these.. So any NORMAL user would not have this issue….

    Configuration–> Sessions -> Prevent Spider Sessions to False…

    Thanks for the help!

  17. Laura James says

    August 29, 2013 at 9:49 am

    Woop woop – thanks for posting your solution Brian – it might help someone else out there 🙂

  18. chris says

    November 3, 2013 at 2:56 am

    I love using zen cart but am having the same problem Tj is. I cannot get the images to show up when posting to facebook.

    The images are located in their own directories. My code looks like this in the Meta tags and the rest of the files were updated as you suggested.

    <meta property="og:image" content="http:///images/” />

    that being said,each of the images are in their own directory, ie /images/precious-moments-dated-christmas/131002.jpg

    Oh and I am using a few modules 2 of which may be impacting this.

    ceon uri mapping manager
    ceon uri mapping seo config

    So how do I get the meta data set for each page when images are in their own directories?

    I appreciate all you are doing to help people like me.

  19. chris says

    November 3, 2013 at 3:43 am

    So Happy, I figured it out

    Both lines with <meta property="og:image" content="http://&lt;? echo $_SERVER["SERVER_NAME"

    Must have <? I had only changed one line because the one for the logo was working, but once I changed the logo line and uploaded, ti works! Again, thank you for your help.

  20. Leo says

    November 11, 2013 at 3:26 pm

    Hi. I have modified your code so that it is dynamic instead of hard coded references to the site name and template directory.

    <meta property="og:title" content="” />
    <meta property="og:url" content="http://” />

    <meta property="og:image" content="http://get_template_dir(”,DIR_WS_TEMPLATE, $current_page_base,’images’).’/logo.png’; ?>” />

    <meta property="og:image" content="http://images/” />

    <meta property="og:site_name" content="”/>
    <meta property="og:description" content="”/>
    <meta property="og:locale" content="” />

    The language setting is still not correct.

  21. BugGrub (@BugGrub_com) says

    November 18, 2013 at 7:13 pm

    Thanks very much, this has been annoying us for ages. Now working like a treat!!!

    Thanks
    BugGrub.com

  22. Amy says

    April 1, 2014 at 2:51 am

    Thanks for this, it works great!
    However what if i want to block certain product images from being shown?

    Eg: i have a folder /images/sensitive/ for certain products,
    that i dont want people to be able to share on facebook,
    but i want them to be able to share everything else under /images

    so just the pics in the sensitive folder not to show, is that possible??

Back to Blog

Testimonials

Thank you for all of your hard work its looks fab and I am over the moon with it!
Amanda MercerAmanda Mercer Ceramics
Thank you guys so much for all that you’ve done helping us to create a really awesome website!! We get such great feedback – everyone loves it & we couldn’t be prouder! Look forward to working with you again soon!
Wild Thyme PlantsWild Thyme Plants
Absolutely fantastically professional web developer – I would highly recommend!!! Thank you so much Kinetic Pulse!
Tania MarstonDoris Designs
It’s been fab working with you – we love the site and certainly going to recommend you!
James DaviesThirty Eight Degrees North
I like it.  I like it a lot !!!

 You have interpreted what I wanted to achieve perfectly considering what you have to play with i.e not redoing the whole thing in the process.

Fiona Simmons-MooreSouth Gloucestershire Parents & Carers
Thanks so much for all your work on this, really appreciated. It’s come on in leaps and bounds since you took over.
Pete KewRedwood Strip Curtains
Amazing and brilliant, Kinetic Pulse have lifted a dream to reality, Highly recommended and great if you are total novice, they know their stuff…Thanks again
Annie LindridgeSalt Yourself Out

Copyright 2026 Kinetic Pulse