8

I know that the correct way to create links in Drupal is to use l($text, $path, array $options = array()). But that only allows for text links. Is there a similar function for creating images that link, or is it OK to just write out the HTML?

10

l() allows for HTML too, you just need to pass it as one of the options:

$link = l($image_html, $path, array('html' => TRUE));

That'll stop the first parameter being passed through check_plain(), so the the full HTML you pass in will be wrapped in the <a> tag.

I'd advise using this method if the alternative is writing the link out manually, you get the benefit of automatic alias-translation and it's less prone to small errors in the HTML (of which I for one always make loads).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.