Ramon Posted October 19, 2018 Share Posted October 19, 2018 Hi all, thanks for looking into my post; I'm trying to add alt-tags to the slider images, but I can only see a description field. Is there some way to add alt-attributes to these types of images? Thanks again Link to comment Share on other sites More sharing options...
pwired Posted October 19, 2018 Share Posted October 19, 2018 Yes you can There is a module for this somewhere that extends the images field functions. But the easiest and fastest way is to use the Processwire api together with the php explode function for this. I have a snippet for this somewhere but cannot find it right now. I will post back when I find it. 1 Link to comment Share on other sites More sharing options...
pwired Posted October 19, 2018 Share Posted October 19, 2018 Here is the snippet <?php $intro = $pages->get('/intro/'); foreach($intro->images as $image) { $image = $image->size(500, 350); $lines = $image->description; $words = explode(",", $lines); echo "<div class=" . '"da-slide"' . ">" . "\n"; echo "<h2>" . $words[0] . "</h2>" . "\n"; echo "<p>" . $words[1] . "</p>" . "\n"; echo "<a href=" . '"#"' . " class=" . '"da-link"' .">" . $words[2] . "</a>" . "\n"; echo "<div class=" . '"da-img"' . ">" . "<img src=" . '"' . $image->url . '"' . " alt=" . '""' . ">" . "</div>" . "\n"; echo "</div>" . "\n"; } ?> In my above example I used php explode for a title, a paragraph and links, but as you see it, you will get the idea. Simply add your alt description as a second word in your image description field and use php explode to echo it inside alt=" . . . " Your image description field will then look like this: image description, alt description, other description, . . . . . Use a comma as a separator 2 Link to comment Share on other sites More sharing options...
Ramon Posted October 19, 2018 Author Share Posted October 19, 2018 Thanks Pwired I will look into this. 1 Link to comment Share on other sites More sharing options...
AndZyk Posted October 19, 2018 Share Posted October 19, 2018 Hello @Ramon, if you want a simple text for the alt tag of your image, than you can just use the description field: https://processwire.com/api/ref/pageimage/ Regards, Andreas Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now