News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Override main image ALT tag

Started by vladast, December 15, 2016, 20:05:24 PM

Previous topic - Next topic

vladast

Hi, I'm wondering how we can override product MAIN image ALT tag?

I've done this on additional images:
default_images_additional.php I have modified code and it looks like:
replace
echo '<a href="'. $image->file_url .'"  class="product-image image-'. $i .'" style="display:none;" title="'. $image->file_meta .'" rel="vm-additional-images"></a>';
with
echo '<a href="'. $image->file_url .'"  class="product-image image-'. $i .'" style="display:none;" alt="'.$image->file_meta.' - '.$this->product->product_name.'" rel="vm-additional-images"></a>';

as you can see on that way I will get Product title beside file_meta under image ALT tag.

Problem is how to override main image ALT TAG to have the same logic?
<?php echo $image->displayMediaFull("",true,"rel='vm-additional-images'"); ?>

I want to modify this to get automatically product title on image title, so I don't have to edit file_meta on every single product.

Thanks

jflash

You need this?
<?php echo $image->displayMediaFull("",true,"alt='".$image->file_meta." - ".$this->product->product_name."' rel='vm-additional-images'"); ?>

Studio 42

Quote from: jflash on December 20, 2016, 14:53:38 PM
You need this?
<?php echo $image->displayMediaFull("",true,"alt='".$image->file_meta." - ".$this->product->product_name."' rel='vm-additional-images'"); ?>

i dont think that this solution work because Vm add own alt.
Try to use :
$image->file_meta .= " - ".$this->product->product_name;
before echo $image->displayMediaFull(...

Raymondo

#3
I also need help with this. Can someone point me to the file where the alt tag is created for the main product image.

If there is no alt text set in the image admin field then by default VM uses the image filename. I would like to change this to use the items product name.

I am using VM3.0.18

Studio 42

Quote from: Raymondo on August 09, 2017, 15:25:06 PM
I also need help with this. Can someone point me to the file where the alt tag is created for the main product image.

If there is no alt text set in the image admin field then by default VM uses the image filename. I would like to change this to use the items product name.

I am using VM3.0.18
It depend the template, but most time it's JOOMLAROOT/templates/YOURTEMPLATE/html/com_virtuemart/productdetails/default_images.php

jjk

Quote from: Raymondo on August 09, 2017, 15:25:06 PM
If there is no alt text set in the image admin field then by default VM uses the image filename. I would like to change this to use the items product name.

I don't know a hack which writes the 'product_name' into the 'Image Alt-Text' field automatically. From the image-SEO point of view this isn't the best idea anyway. In my shop I use a manually written image title (for the eyes of the customer), which displays in the lightbox and a manually written single line description in the image ALT-tag field for the search engines. This works very well, but of course requires a minute per product to write it.

What is the reason for your request? Do you use those cryptic meaningless image file names produced by your digital camera?
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

Raymondo

#6
Thanks for the replies.

Studio 42, I don't think that file is where the actual coding of the 'if image alt is not present then use filename' is. I will look again in case I missed something.

JJK, the image filenames are basically product codes or in some cases product titles with hyphens. I have thousands of products.

Studio 42

If you want modify the tags, i have implement this in Vm Be pro(check in my shop)
Else you need to modify the code.

For eg in the default_images.php for the main mage
if (!empty($this->product->images)) {
$image = $this->product->images[0];
$image->file_meta = $this->product->product_name;
$image->file_description= $this->product->product_name;
$image->file_name = $this->product->product_name;
?>
<div class="main-image">
<?php echo $image->displayMediaFull("",true,"rel='vm-additional-images'"); ?>
<div class="clear"></div>
</div>
<?php
}


This can be applied in the categories too and thumbs, if needed. But it's not a perfect solution if the image itself have to be added in google image for eg. And better is to change with VM Be pro the image descriptions and titles.
Note that this code need to be changed in the modules too and any view that display the images.

Raymondo

Studio 42, Thanks! I didn't even think about batching it :-) I can add some custom text to the product name to create the alts etc.

I will be sure to look at your shops extensions to see if there is something I can purchase as way of thanks for the nudge in the right direction.

Milbo

you can see that I already added this
file components/com_virtuemart/views/productdetails/tmpl/default_images_additional.php

$descr = '';// $image->file_description;


it is just for another use case.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/