php - Add target & rel without javascript -
php - Add target & rel without javascript -
i have links need add together target="_blank" , rel="nofollow noreferrer". not have acess core code way managed jquery.
my html is.
<div class="tlink"> <p> <a href="http://linkhere.com" title="tlink title here">tlink</a> </p> </div> my jquery code:
$( '.tlink p a' ).attr( 'target', '_blank' ); $( '.tlink p a' ).attr( 'rel', 'nofollow noreferrer' ); however not work if end user not have javascript enabled in browser. so, there other way php? or in lastly case within template.php file of drupal theme?
thanks
for 99% of cases you'll able override theme_link() in template.php:
function mytheme_link($variables) { $variables['options']['attributes']['target'] = '_blank'; $variables['options']['attributes']['rel'] = 'nofollow noreferrer'; homecoming '<a href="' . check_plain(url($variables['path'], $variables['options'])) . '"' . drupal_attributes($variables['options']['attributes']) . '>' . ($variables['options']['html'] ? $variables['text'] : check_plain($variables['text'])) . '</a>'; } i 99% because premise relies on every module in installation 'behaving' itself, , using l() function prepare links. if don't, you'll need patch each module separately.
also bear in mind above code nuke existing target/rel attributes (not append them), logic might need bit more complicated compensate.
php jquery drupal target rel
Comments
Post a Comment