You are here


Drupal 7 convert node edit tabs to contextual links

Add the following code to your template.php in your theme: (without the php tags, and replace YOURTHEME with your theme name)

function YOURTHEME_menu_local_task($variables) {
$link = $variables['element']['#link'];
$link['localized_options']['html'] = TRUE;
'<li>'.l($link['title'], $link['href'], $link['localized_options']).'</li>'."\n";
YOURTHEME_menu_local_tasks($variables) {
// Add contextual links js and css library
drupal_add_library('contextual', 'contextual-links');
$output = '';
  if (!empty(
$variables['primary'])) {
$variables['primary']['#prefix'] = '<div class="contextual-links-wrapper"><ul class="contextual-links">';
$variables['primary']['#suffix'] = '</ul></div>';
$output .= drupal_render($variables['primary']);
  if (!empty(
$variables['secondary'])) {
$variables['secondary']['#prefix'] = '<ul class="tabs secondary clearfix">';
$variables['secondary']['#suffix'] = '</ul>';
$output .= drupal_render($variables['secondary']);

Then add a div with the class contextual-links-region around your main content /node area <div class="contextual-links-region">

We've also noticed that there must be at least one block on the node pages to make sure contextual links are loaded. UPDATE: The drupal_add_library line should fix this, but it may need to go in the menu_local_task hook for some themes (or for some reason) as shown in the comment below.

Contextual Links

Need A Developer? Contact Us