Bayu Angga Satrio
Bayu Angga Satrio

Reputation: 131

how to insert alt tag inside anchor tag in php?

    <div >
        <a href="<?=site_url()?>"><?=img('logo.png',array('class'=>'logo'))?></a>
    </div>

I want to add an ALT TAG for logo.png

thanks

Upvotes: 1

Views: 717

Answers (4)

Kanishka Panamaldeniya
Kanishka Panamaldeniya

Reputation: 17576

If you are using code igniter framework you can do it like this

From The Codeigniter Documentation

$image_properties = array(
          'src' => 'images/picture.jpg',
          'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',
          'class' => 'post_images',
          'width' => '200',
          'height' => '200',
          'title' => 'That was quite a night',
          'rel' => 'lightbox',
);

img($image_properties);

img()

Upvotes: 1

Parth Chavda
Parth Chavda

Reputation: 1829

after looking your code,you might be used "codeigniter" framework and below is a solution for your code.below code is showing how to add a attribute in img function.you need to just pass an array,that contain a attribute and there value.

<div>
<a href="<?=site_url()?>">
<?= img(array('src'=>'image/logo.png', 
                    'alt'=> 'alt information',
                     'class'=>'logo')); ?>
</a>
</div>

please correct your syntax.

Upvotes: 1

Prafulla Kumar Sahu
Prafulla Kumar Sahu

Reputation: 9693

  <div >
        <a title="your site" href="<?=site_url()?>"><?=img('logo.png',array('class'=>'logo'))?></a>
    </div>

You can not use alt attribute in anchor tag, instead use title attribute or , if it is an image as in your case it is a logo . You can use img tag and alt attribute.

may be something like with little bit modification.

<a href="<?=site_url()?>"><img src="<?=img('logo.png',array('class'=>'logo'))?>" alt="your site" /></a>

Upvotes: 1

Juan Elfers
Juan Elfers

Reputation: 780

Guess you are using some kind of framework, so the answer could not be correct. Please, try this:

<div>
    <a href="<?=site_url()?>"><?=img('logo.png', array('class'=>'logo', 'alt'=>'Write here your alternative text'))?></a>
</div>

Upvotes: 1

Related Questions