Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
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
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
Pages: 1