page title in image alt tag

Post Reply
essentialsoflife
Ssr. Bludit
Posts: 15
Joined: Sun May 12, 2019 12:04 pm

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>
User avatar
Jay
Master Bludit
Posts: 133
Joined: Mon Feb 11, 2019 8:41 pm

you can't echo an echo ;)
Change what is inside alt to below fix

Code: Select all

alt="'.$page->title().'"></a>';
essentialsoflife
Ssr. Bludit
Posts: 15
Joined: Sun May 12, 2019 12:04 pm

Oh! I did not know that! Thank you so much - works great now! :D
Post Reply