Page 1 of 1

page title in image alt tag

Posted: Thu May 16, 2019 6:13 pm
by essentialsoflife
I have a set of banner images that I am using in the header and would like the page title to be listed in the alt tag. However, what is being listed is the php code instead of the page title. Is there a way to do this? This is what I have:

Code: Select all

<?php

$banner1 = '<a href="https://plexusworldwide.com/essentialsoflife/home" target="_blank"><img class="aligncenter" src="http://cdn.essentialsoflife.net/bludit-test/bl-themes/plexathon/img/slim-01.jpg" alt="<?php echo $page->title(); ?>"></a>';
$banner2 = '<a href="https://plexusworldwide.com/essentialsoflife/home" target="_blank"><img class="aligncenter" src="http://cdn.essentialsoflife.net/bludit-test/bl-themes/plexathon/img/slim-02.jpg" alt="<?php echo $page->title(); ?>"></a>';
$banner3 = '<a href="https://plexusworldwide.com/essentialsoflife/home" target="_blank"><img class="aligncenter" src="http://cdn.essentialsoflife.net/bludit-test/bl-themes/plexathon/img/slim-03.jpg" alt="<?php echo $page->title(); ?>"></a>';

$banners = array($banner1, $banner2, $banner3); 
shuffle($banners);
?>

<div>
  <?php echo $banners[0] ?>
</div>

Re: page title in image alt tag

Posted: Fri May 17, 2019 5:36 pm
by Jay
you can't echo an echo ;)
Change what is inside alt to below fix

Code: Select all

alt="'.$page->title().'"></a>';

Re: page title in image alt tag

Posted: Fri May 17, 2019 9:56 pm
by essentialsoflife
Oh! I did not know that! Thank you so much - works great now! :D