Page 1 of 1

Re: php in image alt tag

Posted: Fri Aug 24, 2018 2:26 pm
by Christopher
You can use PHP to display the value of a variable anywhere in a PHP page. There are several different variations to do this:

Code: Select all

// show just the $title variable
<img src="images/logo/logo.png" alt="<?php echo $title; ?>" title="">
// OR show the whole tag with single quotes by concatenating
<?php echo '<img src="images/logo/logo.png" alt="' . $title . '" title="">'; ?>
// OR show the whole tag and escape double quotes
<?php echo "<img src=\"images/logo/logo.png\" alt=\"$title\" title=\"\">";  ?>

Re: php in image alt tag

Posted: Sat Aug 07, 2021 2:16 am
by kiash
You can also use printf or spritf function to display alt tags