VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: modernmagic on April 06, 2022, 08:24:28 AM

Title: add Image Alt-Text to all products
Post by: modernmagic on April 06, 2022, 08:24:28 AM
My site has 900 products they all need "Image Alt-Text". 

Is there a way to generate the Image Alt-Text from the "file title"(and remove the file extension if possible) from all 900 products at once? 
Title: Re: add Image Alt-Text to all products
Post by: pinochico on April 06, 2022, 08:43:05 AM
yes, of course

Find place, where is generate image in PHP and add as params.
We add this hack into VM all time, we don't wait for DEV team :)

But.

You have to go to this file:
administrator/components/com_virtuemart/helpers/mediahandler.php

Find this code:

Quote
if(empty($this->file_meta)){
         if(!empty($this->file_description)){
            $file_alt = $this->file_description;
         } else if(!empty($this->file_name)) {
            $file_alt = $this->file_name;
         } else {
            $file_alt = '';
         }
      } else {
         $file_alt = $this->file_meta;
      }

and change for you.

And in function displayIt you can change too - add width, height or aspect-ratio for eliminate CLS.

We use this:

Quote$image = '<img src="' . $image_href . '" alt="' . $file_alt . '" title="' . $file_alt . '" ' . $imageArgs . ' width="' . $size[0] . '" height="' . $size[1] . '" style="aspect-ratio: ' . $size[0] . ' / ' . $size[1] . '"/>';