Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2026-03-13 22:48:31

mwr
Member
From: Canada
Registered: 2006-01-31
Posts: 171
Website

article_image alt

Is there an easy way to add alt to article_image? I thought <txp:article_image alt=“icon for <txp:title />” /> might work.


Mark

Offline

#2 Yesterday 10:11:50

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,243
Website GitHub

Re: article_image alt

As you’ve discovered, alt isn’t an attribute of the article_image tag. You have two options:

You can use the trim and replace tags to “search and replace” the tag string:

<txp:article_image trim='/alt="(.+?)"/' replace='alt="Icon for <txp:title />"' />

The weird-looking use of single quotes for the attributes here is because the double quote is part of the search and replace values (and also because using a tag inside an attribute requires single quotes).

Or you can do:

<txp:if_article_image>
    <txp:images>
        <img src="<txp:image_url />" alt="Icon for <txp:title />">
    </txp:images>
</txp:if_article_image>

which gives you greater flexibility. You can add extra image attributes here if you like using the image_info tag. txp:images tries to be context aware so will use the article image if it’s available. It’s wise to wrap this tag in if_article_image because if no article image is specified it will output all the last ten images if I recall correctly.


TXP Builders – finely-crafted code, design and txp

Offline

#3 Yesterday 22:24:05

etc
Developer
Registered: 2010-11-11
Posts: 5,693
Website GitHub

Re: article_image alt

It should not be difficult to add alt attribute to <txp:article_image /> if needed. Needed?

Offline

#4 Yesterday 22:55:25

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,518
Website GitHub

Re: article_image alt

etc wrote #342945:

It should not be difficult to add alt attribute to <txp:article_image /> if needed. Needed?

Does it not output the alt associated with the image asset already, if it’s set? Pretty sure it does. Isn’t that the correct place to assign the alt text?

If this is for those instances where people want to override it manually, or to include tags, that’s cool. I’m all for that. But shouldn’t we extend the alt override ability to the image/thumbnail tag too? Or allow the alt/caption to somehow by escape-able so you could put Icon for <txp:title /> into the alt field and have it parsed on display, if you choose an appropriate escape value?

EDIT: Mind you, that’s a lot of extra work to add it to each image so, yeah, being able to override the alt at the tag level might be a very neat feature.

btw, I added this kind of functionlity in my img_alt plugin. So if we don’t implement something similar in core, there’s a path to do it for mwr.

Last edited by Bloke (Yesterday 23:00:42)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#5 Today 03:10:17

mwr
Member
From: Canada
Registered: 2006-01-31
Posts: 171
Website

Re: article_image alt

Thanks for the tips. I think I’ll leave well enough alone. I’ve got 444 icons (at last count) and it’s not that crucial that they have an alt :)


Mark

Offline

Board footer

Powered by FluxBB