PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Dec 10, 2018 11:34 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: php in image alt tag
PostPosted: Wed Aug 22, 2018 12:33 pm 
Offline
Forum Contributor

Joined: Tue Sep 30, 2014 5:27 am
Posts: 420
I was just seeing if it was possible to use php in image alt tag. I have a header.php file has the logo url as
Syntax: [ Download ] [ Hide ]
<a href="/"><img src="images/logo/logo.png" alt="" title=""></a>
and the page title tag as
Syntax: [ Download ] [ Hide ]
<title><?php echo $title; ?></title>
and on the inner pages, I have the code
Syntax: [ Download ] [ Hide ]
$title = "PAGE TITLE";


Is it possible to have the pages title tag in the image alt tag in the header.php file or can I create a alt tag in the inner page php file, maybe something like
Syntax: [ Download ] [ Hide ]
$alttage="alt tag 1";
and then on the image alt tag in header.php file
Syntax: [ Download ] [ Hide ]
<a href="/"><img src="images/logo/logo.png" alt="$alttag" title=""></a>


Is there some way of doing that?

Thank you in advance


Top
 Profile  
 
 Post subject: Re: php in image alt tag
PostPosted: Wed Aug 22, 2018 12:46 pm 
Offline
Forum Contributor

Joined: Tue Sep 30, 2014 5:27 am
Posts: 420
I think I have done it, I have done the following to my header.php file

Syntax: [ Download ] [ Hide ]
<img src="images/logo/logo.png" alt="<?php echo $title ?>" title="">


I now uses the page title as the alt attribute


Top
 Profile  
 
 Post subject: Re: php in image alt tag
PostPosted: Fri Aug 24, 2018 2:26 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13583
Location: New York, NY, US
You can use PHP to display the value of a variable anywhere in a PHP page. There are several different variations to do this:

Syntax: [ Download ] [ Hide ]
// 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=\"\">";  ?>
 

_________________
(#10850)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Exabot [Bot] and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group