以编程方式在菜单项上添加rel和title属性

时间:2012-10-24 14:20:51

标签: drupal

我有一个菜单建立了这个whay:

function hook_menu()
{
    $items['footer_callback'] = array(
        'type' => MENU_CALLBACK,
        'access callback' => true,
        'page callback' => 'drupal_get_form',
        'page arguments' => array('tac_webforms_footer_form'),
        'menu_name' => 'footer-menu',
        'title' => 'Newsletter'
    );
}

我是否可以通过options属性传递reltitle html属性到创建的<a>标记?

根据docs,我可以传递我正在讨论的options密钥,但这不起作用。

P.S。:我想以编程方式进行,最好不使用任何模块,

1 个答案:

答案 0 :(得分:0)

这将为主题级别的大多数链接添加标题属性,但取决于某些模块。也许你可以使用rel属性。

/**
 * 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']);
}
相关问题