WBCE Home | WBCE Hilfe | WBCE Addon Repository | Impressum | Datenschutz

WBCE CMS Forum

WBCE CMS – Way Better Content Editing.

You are not logged in.

#1 03.10.2019 21:01:33

losttrip
Member

If no Image alt attribute set use item Title

I am working with OneForAll OFA and am trying to do a check to see if the item image has an "alt" attribute set.  If not, then I want to insert the item [TITLE] automatically for all images.

I have been trying to achieve this by editing the modify_item.php file line ~465:

<input type="text" name="images[<?php echo $img_id; ?>][alt]" style="width: 150px;" maxlength="255" value="<?php echo $image['alt']; ?>" />

I can force it to use [TITLE] by changing it to:

<input type="text" name="images[<?php echo $img_id; ?>][alt]" style="width: 150px;" maxlength="255" value="[TITLE]" />

But I don't want to force it or over any alt tag a user has imput.  I want to check first.  I've tried if else, but am doing something wrong, because I keep getting white screens.

Sorry for the noob question.  Thanks in advance for your time.

Offline

#2 04.10.2019 07:19:27

florian
Administrator

Re: If no Image alt attribute set use item Title

You can achieve this by modifying the save_item.php. Change line

if (!empty($image['title']))   { $image['alt'] = $image['title']; }

to

if (empty($image['title']))   { $image['alt'] = $title; }

Offline

Liked by:

losttrip

#3 08.10.2019 17:38:07

losttrip
Member

Re: If no Image alt attribute set use item Title

Thank you for steering my in the right direction.

Because I want to maintain the ability to put custom text in the ['title'] Attribute dialogue and it NOT be automatically used if the 'alt' attribute is empty, I used this:

if (empty($image['alt'])) { $image['alt'] = $title; }

So that ONLY the item TITLE is used, if the alt attribute is empty.

Offline

#4 08.10.2019 17:50:17

florian
Administrator

Re: If no Image alt attribute set use item Title

Well whatever, maybe I've understood you wrong. But you wrote this

if the item image has an "alt" attribute set.  If not, then I want to insert the item [TITLE] automatically for all images.

what differs from this

I want to maintain the ability to put custom text in the ['title'] Attribute dialogue and it NOT be automatically used if the 'alt' attribute is empty,

But if you found a solution for your need, all the better.

Offline

#5 08.10.2019 18:28:20

losttrip
Member

Re: If no Image alt attribute set use item Title

Sorry, if I sounded ungrateful.  I am not.  I appreciated your help.

I was/am probably not being clear with my terms.  I apologize.

Here is the item [TITLE] I am referring to:
item TITLE

and here is the image HTML ['title'] Attribute dialogue I am referring to:
HTML title Attibute

In my test of your code solution:

if (empty($image['title']))   { $image['alt'] = $title; }

It works perfectly IF the item image HTML ['title'] Attribute dialogue IS Empty.  Then it uses the Item [TITLE] for the 'alt'.  That's great!

...But if the HTML ['title'] Attribute dialogue is NOT empty, then the HTML ['title'] Attribute text is used for the 'alt' attribute... and I don't want that.  I want to use the item [TITLE] for the alt (if the alt is empty).

I want users to be able to enter image HTML ['title'] Attribute text (which is shown as a tooltip when hovering the image) if they want, without that text being used as the alt.

This is what the solution I ended up using seems to accomplish.  It's working for me at least.

Hope this helps somewhat to clarify.

Thank you once again.

Offline

Board footer

Powered by FluxBB

up