Posted By

shrop on 08/13/08


Tagged

drupal Themes


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

luman
basicmagic
troynt
panatlantica


Open external URLs in a new window - Drupal


 / Published in: PHP
 

URL: http://agaricdesign.com/note/open-external-urls-a-new-window

PHP Template override by Benjamin Melançon of Agaric Design.

  1. <?php
  2. /**
  3. * Override theme_menu_item_link
  4. * <a href="http://api.drupal.org/api/function/theme_menu_item_link/5
  5. " title="http://api.drupal.org/api/function/theme_menu_item_link/5
  6. ">http://api.drupal.org/api/function/theme_menu_item_link/5
  7. </a> */
  8. function phptemplate_menu_item_link($item, $link_item) {
  9. // make external links open in new windows
  10. $attributes = !empty($item['description']) ? array('title' => $item['description']) : array();
  11. if (strpos($link_item['path'], 'http://') === 0 || strpos($link_item['path'], 'https://') === 0) {
  12. $attributes['target'] = '_blank';
  13. }
  14. return l($item['title'], $link_item['path'], $attributes, isset($item['query']) ? $item['query'] : NULL);
  15. }
  16. ?>

Report this snippet  

You need to login to post a comment.