Open external URLs in a new window - Drupal


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.