Daniel Toebe
Daniel Toebe

Reputation: 2719

How to add attributes to hard coded images in Drupal 7 themes

I am using

<?php echo theme('image', array('path' => drupal_get_path('theme', 'themename') .'/img/demo.png')); ?>

To hard code images into my Drupal 7 theme. My question is how do I add attributes like "id", "class" or "alt"?

Upvotes: 0

Views: 490

Answers (1)

Mike Vranckx
Mike Vranckx

Reputation: 5577

To add extra attributes, you pass an array attributes with the necessary key => value pair. Identical for the alt attribute.

For example:

print theme('image', array(
    'path' => drupal_get_path('theme', 'themename') . '/img/demo.png',
    'alt' => 'my alt content',
    'attributes' => array(
        'id' => 'myId',
        'class' => 'myClass',
    ))
);

Upvotes: 1

Related Questions