On my page where there is an image, I added the alt and title attributes, and these fields are sometimes empty, sometimes they are not.
Now I'm taking it out like this:
<?php foreach ($images as $image) { ?> <img src="<?= $image->getImageUrl() ?>" alt="<?= $image->image_alt ?>" title="<?= $image->image_title ?>"> <?php } ?> And I need to add a check here, when these fields are empty, then do not display the alt and title attributes on the page.
I try to do something like this, but they still show up:
<?php foreach ($images as $image) { ?> <img src="<?= $image->getImageUrl() ?>" <?php if (!empty($image->image_alt) { ?> alt="<?= $image->image_alt ?>" <?php } ?> <?php if (!empty($image->image_title) { ?> title="<?= $image->image_title ?>" <?php } ?>> <?php } ?> Also tried like this:
<?php foreach ($images as $image) { ?> <img src="<?= $image->getImageUrl() ?>" <?php if (!empty($image->image_alt) && !empty($image->image_title)) { ?> alt="<?= $image->image_alt ?>" title="<?= $image->image_title ?>"> <?php } ?> <?php } ?>