Author Topic: Override main image ALT tag  (Read 414 times)

vladast

  • Beginner
  • *
  • Posts: 36
Override main image ALT tag
« on: December 15, 2016, 20:05:24 pm »
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
Code: [Select]
echo '<a href="'. $image->file_url .'"  class="product-image image-'. $i .'" style="display:none;" title="'. $image->file_meta .'" rel="vm-additional-images"></a>';with
Code: [Select]
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?
Code: [Select]
<?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

  • 3rd party VirtueMart Developer
  • Beginner
  • *
  • Posts: 13
Re: Override main image ALT tag
« Reply #1 on: December 20, 2016, 14:53:38 pm »
You need this?
Code: [Select]
<?php echo $image->displayMediaFull("",true,"alt='".$image->file_meta." - ".$this->product->product_name."' rel='vm-additional-images'"); ?>

Studio 42

  • Contributing Developer
  • Full Member
  • *
  • Posts: 2142
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Override main image ALT tag
« Reply #2 on: December 23, 2016, 11:09:35 am »
You need this?
Code: [Select]
<?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 :
Code: [Select]
$image->file_meta .= " - ".$this->product->product_name;before echo $image->displayMediaFull(...

Raymondo

  • Beginner
  • *
  • Posts: 3
  • A beginner
Re: Override main image ALT tag
« Reply #3 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

Studio 42

  • Contributing Developer
  • Full Member
  • *
  • Posts: 2142
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Override main image ALT tag
« Reply #4 on: August 10, 2017, 12:37:35 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

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3147
  • using Piwik instead of Google Analytics
Re: Override main image ALT tag
« Reply #5 on: August 10, 2017, 15:29:32 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

  • Beginner
  • *
  • Posts: 3
  • A beginner
Re: Override main image ALT tag
« Reply #6 on: August 10, 2017, 18:50:45 pm »
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

  • Contributing Developer
  • Full Member
  • *
  • Posts: 2142
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Override main image ALT tag
« Reply #7 on: August 10, 2017, 21:08:21 pm »
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
Code: [Select]
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

  • Beginner
  • *
  • Posts: 3
  • A beginner
Re: Override main image ALT tag
« Reply #8 on: August 11, 2017, 01:07:13 am »
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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9175
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Override main image ALT tag
« Reply #9 on: August 11, 2017, 16:10:54 pm »
you can see that I already added this
file components/com_virtuemart/views/productdetails/tmpl/default_images_additional.php
Code: [Select]
$descr = '';// $image->file_description;

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