3

In views fields like [Content: Title] and [Content: Taxonomy] there is the possibility to have the content displayed as link. Is it also possible to equip these link with a html 'title' attribute?

Alternatively, is it possible to equip all links on a drupal site with html 'title' attributes?

3

This will add title attributes to most links, depends with some modules though.

/**
 * Add title attribute to any link that doesnt have a title already
 */
function YOURTHEME_preprocess_link(&$vars) {
    // If title set and not empty dont do anything
    if (isset($vars['options']['attributes']['title']) && !empty($vars['options']['attributes']['title'])) {
        return;
    }

    // Use the link text as the title
    $vars['options']['attributes']['title'] = strip_tags($vars['text']);
}
| improve this answer | |
2

There are multiple ways your issue can be addressed. Please find answers below that will resolve some of your questions.

  • All Menu Links created using Drupal Core Menu Module i.e using User Interface

You can use Menu Attributes module to add title attribute.

  • Links exposed in custom module

You can use l function to create a link with attributes.

  • Views fields

You can use rewrite results option to rewrite content and add html as you like with attributes to a tag.

UPDATED:

Uncheck the setting in title field settings as shown below.

enter image description here

| improve this answer | |
  • Thanks for your answers! I am however not using any menus on my site at all. I managed to achieve a rewrite for the Title field: <div title = '[title]'> [title]</div> (reads funny doesn't it? ;) But when I rewrite <div title = '[field_taxonomy]'> [field_taxonomy]</div>, the title gives the full URL... – Johann_Schmidt Oct 23 '12 at 10:04
  • I meant, the title popup shows the full html tag: <a href="site.com/cat/foo">foo</a> – Johann_Schmidt Oct 23 '12 at 10:11
  • You need to uncheck link setting in views title field settings... See my updated answer ! For taxonomy term you just need to print the term name with out any formatting.. Uncheck "Link this field to its term page" – Anil Sagar Oct 23 '12 at 10:42
  • I got it working for the title field, as I described above. Unchecking "Link this field to its term page" would remove the link. With field_taxonomy, I got it to work in plain text format, with the rewrite mentioned above and 'output field as link', link path /cat/[field_taxonomy] and path set absolute. Phew. – Johann_Schmidt Oct 23 '12 at 11:08

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.