This post is about How to optimize Prestashop in Search Engine Optimization (SEO) perspective by altering images naming convention.
3) How to name the images
It’s been recognised within SEO generally that file names can have an impact on results. This is reflected too within search engine optimisation for images. Use dashes to separate keywords in the file name, rather than underscores.
This quote is from http://blog.webdistortion.com/2009/03/26/seo-for-images-photography/
In this post we will try to optimize Prestashop search engine result by modify the images name used in Prestashop. We have another post which discuss how to reduce Prestashop size by eliminating some useless images. You can refer to this post to understand how Prestashop generate a lot of images varies from the mini one to large one.
This tips is my answer for Prestashop forum thread How to rename images automatically. We use simple technique to modify Prestashop engine, same technique in our previous post.
#1 Modify AdminImages.php
This file is located at ../prestashop/admin/tabs/AdminImages.php. Following our snippet code from AdminImages.php
/* Regenerate products images */
$errors = false;
foreach ($productsImages AS $k => $image)
{
if (file_exists(_PS_PROD_IMG_DIR_.$image['id_product'].'-'.$image['id_image'].'.jpg'))
//modification by gm.computer@yahoo.com
//http://ardianys.com/
$product = new Product($image['id_product']);
$langdefault = Configuration::get('PS_LANG_DEFAULT');
//end of mod
foreach ($productsTypes AS $k => $imageType)
{
//new code
$newFile = _PS_PROD_IMG_DIR_.$image['id_product'].'-'.$image['id_image'].'-'.$product->link_rewrite[$langdefault].'-'.stripslashes($imageType['name']).'.jpg';
//old code
//$newFile = _PS_PROD_IMG_DIR_.$image['id_product'].'-'.$image['id_image'].'-'.stripslashes($imageType['name']).'.jpg';
if (!imageResize(_PS_PROD_IMG_DIR_.$image['id_product'].'-'.$image['id_image'].'.jpg', $newFile, intval($imageType['width']), intval($imageType['height'])))
$errors = true;
}
}
We add some code in AdminImages.php Prestashop Back Office. Following simple explanation to this new code.
$product = new Product($image['id_product']);
Getting the product object by create new instance of Product class by using id_product paramater.
$langdefault = Configuration::get('PS_LANG_DEFAULT');
We will using link_rewrite values for each product, we need default language because this variable is language dependent.
$newFile = _PS_PROD_IMG_DIR_.$image['id_product'].'-'.$image['id_image'].'-'.$product->link_rewrite[$langdefault].'-'.stripslashes($imageType['name']).'.jpg';
We have new snippet code to generate modified name for prestashop images. We hope this technique can boost our Prestashop SEO by inserting $product->link_rewrite[$langdefault] in prestashop images.
#2 Modify Link.php
In step #1, we have altered how images name are generated by Prestashop. The second problem is that prestashop themes system still use the old names to display their images. You will get website without product images for that.
So we have to modify how Prestashop themes system call our modified images name. File Link.php is located at ../prestashop/classes/Link.php Following our modified Link.php class.
public function getImageLink($name, $ids, $type = null)
{
return ($this->allow == 1) ? (__PS_BASE_URI__.$ids.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_PROD_DIR_.$ids.'-'.$name.($type ? '-'.$type : '').'.jpg');
}
We have done this modification not more than an hour, please give any response or may be bug in this modification by commenting this post. Your support make this blog fresh. Thanks for reading.
We have try this SEO tips in Prestashop version 1.2.5, please give us any update from another version of Prestashop do you use.
Our results:
Actually Prestashop already has image name url when friendly url is enabled. But there is a difference between default prestashop image url and our technique. I think Google prefer id_product-id_image-produk_name-image_type.jpg syntax better than id_product-id_image--image_type/produk_name.jpg because there are new slash in image name.
This links go to same article
prestashop seo, prestashop Friendly URL, prestashop link_rewrite, prestashop Link to database cannot be established, ardianys seo prestashop, prestashop all pages but the Web address you entered is no longer available, prestashop seo tips, seo for prestashop, link to database cannot be established prestashop, prestashop seo lang, prestashop rename home category, prestashop rename link, prestashop rewrite, prestashop rewrite product image names, prestashop Were sorry but the Web address you entered is no longer available, prestashop rewrite rule module image, prestashop SEO support, prestashop rewrite url product id in end, prestashop seo pictures, prestashop send us your photo,
Related posts:
PrestaShop Diet Program – PrestaShop Modification Tutorial Series
The need for speed Despite its technical sophistication and advanced functionality, the PrestaShop e-Commerce Solution is very light (around 6 MB not including translation files), so it’s easy to download, install, and update. PrestaShop is so lightweight and speedy, even customers with slow connection speeds will enjoy buying from you!...
How to add new hook in PrestaShop engine – Prestashop Modification Tutorial Series
This is random post under Prestashop Modification Tutorial Series. You have to already familiar with Object Oriented Programming in PHP, Smarty, module programming in PrestaShop, and able to manage MySql database either using web interface like PhpMyAdmin, or using command line in Windows command prompt / shell. In this tutorial...




So what will be the new of the image?, the product name isit? or the url from the product.? Thanks . This is very useful. I will wait for your response before trying it.
The new name of images is follow this rule
id-product > id-image > product-friendly-URL > image-typeYou can view product-friendly-URL variable while configuring SEO field in product form. You need to click “Click here to improve product’s rank in search engines (SEO)” to show it. This variable value is automatically added while you typing product name, but this variable is editable.
Thanks for your comment.
How do i confirm if the image names have been changed?
Im using 1.2.4
Right click on the image an open image in new tab or view the html source.
Awesome its working great…..
its so great tecnik to increace traffik for search engine
makin mantabbb broo
.-= eko prasetyo´s last blog ..download aplikasi chatting dan internet gratis untuk handphone =-.
Sorry but this hack is working only by regeneration of the thumbnails (../prestashop/admin/tabs/AdminImages.php).
How to do same thing in the product images page ?
Yups, I missed about this, thanks for your correction. I’ll publish the update in my next post if I have made a solution.
I think that Google prefers that names begin by significative words :
“chicha-pumpkin-home-10-57.jpg”
is better than
“10-57-chicha-pumpkin-home-10.jpg” no ?
So I replaced :
$newFile = _PS_PROD_IMG_DIR_.$image['id_product'].’-’.$image['id_image'].’-’.$product->link_rewrite[$langdefault].’-’.stripslashes($imageType['name']).’.jpg’;
by :
$newFile = _PS_PROD_IMG_DIR_.$product->link_rewrite[$langdefault].’-’.stripslashes($imageType['name']).’-’.$image['id_product'].’-’.$image['id_image'].’.jpg’;
Renaming of images by regeneration is ok but thumbnails are not visible now ;-(
Very sorry but my PHP is very beginner …
Would you like to help me in this sense about the link modification ?
Hi, thanks for your suggestion. Its true if Google prefers the image file names begin by significative words. I’ll publish the update in next post so we have two different choice.
Regards.
Hi,
I don’t understand the second part. The link.php code listed above (getImageLink) is similar to what I have already in my file. I see no difference (I’m using v 1.2.2).
So what needs to be modified in link.php?
I did the first part (modified AdminImages.php ), then has regenerated the product images. Now my products are displayed without images at all in the front office. Looks like the link need to be repaired but Has no clue about wha tot do.
Thanks.
Franck
Hi Bugnet,
I have test this modification in prestashop 1.2.1 and 1.2.5,
But sorry if I missed to paste to modified code instead the original. I missed tho paste
.'-'.$nameI have update my post so please check it again. But I got suggestion from Hugues to make the image name begins with the product name instead the id, So may be you’ll be interested with my next post about this update.
Regards.
Hi again,
Second issue. I relaized the part #1 mod has effectively re-created new images, in all sizes, adding words taken from the image caption in the file name.
BUT those words are the same for all products, taken from the caption of the first product created in the catalogue. So useless indeed.
I checked ten times, did exactly the same you described above. So lost.
Rgds
Franck
Would you like to attach the screenshot of your product images folder in /prestashop/img/p/ so I can check this.
This words are taken from the product URL rewriting variable. So you will get same image name prefix to all of this product combinations.
Dear All, I have an update about this Prestashop Image SEO tips, this update include product name as prefix of images file name and enable images name SEO manipulation while adding new product via BO, not just by clicking thumbnail regeneration. Thanks for all for your correction.
Regards.
Hi,
Thanks for the reply and correction.
Reading your answer, I understood URL rewritting must be activated in Presta, right ? It was not on my side and has just done it now, then regenerated the images. Same result, all images names includes words from the first product of catalog (with the exception of about two/three products, for which the name looks ok – very strange, may be something corrupted in my database).
Another poppoing up issue, now that URL rewritting is activated, the product list pages cannot be called anymore, Presta return this message: “We’re sorry, but the Web address you entered is no longer available”
(ex:http://127.0.0.1/category.php?id_category=5 has been renamed http://127.0.0.1/5-restoration and is not found)
Any idea what I made wrong ?
Note: Made those mod and tests only locally for now, using Xampp. Is it an issue ?
Will make it on the production serveur only when I’m sure it is working locally first.
How can I attach a screenshow here ?
Is your last update (referring your last post), already available for sharing ?
Regards
Franck
OK URL rewritting working now, was just a matter of regenerating the htaccess file.
Remains the initial issue, file names include wrong word and images are not displayed (not found)
Franck
Hi
I’m lost.
URL rewritting is working fine, get now new and correct file names, but still cannot have them being displayed.
I think there is something wrong with link.php this code:
return ($this->allow == 1) ? (__PS_BASE_URI__.$ids.($type ? ‘-’.$type : ”).’/’.$name.’.jpg’) : (_THEME_PROD_DIR_.$ids.’-’.$name.($type ? ‘-’.$type : ”).’.jpg’);
It displays correctly images with the old name, but not the image with the new long names.
I’n too new to php to troubleshoot myself.
Rgds
Franck
Hi Ardian,
Do you have an update with the category code rewriting?
Where is the new post you are talking about the 30 of december?
Thanks a lot for your code
top banget boss infonya salam kenal ya
What should I do to get my site towards the top of google do I have to have to hire an seo business or can I do it myself thanks for the help