Contextual links for a custom module I want to add in a contextual link to a block.

The block shows up in different pages, not just a specific page.

Here is my current setup 

$block['content'] =array(
    '#markup' =&gt; _get_markup(),
    '#attached' =&gt; array(
        'css' =&gt; array(
            drupal_get_path('module', 'module_name') . '/css/main.css',
        ),
        'js' =&gt; array(
            drupal_get_path('module', 'module_name') . '/js/main.js'
        ),
    ),
    '#contextual_links' =&gt; array(
        'add content' =&gt; array('add/content/', array('content')),
    ),
);


Based on the documentation, this should work for drupal 7 but it does not for me.
To be able to add your custom contextual link, you first need to check the Contextual links module is enabled. Even though you define everything correctly, it would not show, if it is disabled. Also, you need to set context to MENU_CONTEXT_INLINE in your menu items.

/**
 * Implements hook_block_view().
 */
function example_block_view($delta = '') {
  $block = array();
  switch($delta) {
    case 'my_custom_block':
      $block['subject'] = t('Example Block');
      $block['content'] = array(
      '#markup' =&gt; _get_markup(),
      '#contextual_links' =&gt; array(
          'add content' =&gt; array('add', array('node')),
      ));
      break;
    default:
      break;
  }

  return $block;
}

/**
 * Implements hook_menu().
 */
function example_menu() {
    $items['add/%/content'] = array(
        'title' =&gt; 'Add Content',
        'type' =&gt; MENU_LOCAL_ACTION,
        'context' =&gt; MENU_CONTEXT_INLINE,
        'page callback' =&gt; 'contextual_node_page',
        'page arguments' =&gt; array(1),
        'access callback' =&gt; TRUE,
    );

    // To use local task menu items, there must be a parent page.
    $items['add'] = array(
        'title' =&gt; 'Contextual Link Page',
        'page callback' =&gt; 'contextual_node_page',
        'page arguments' =&gt; array(1),
        'access callback' =&gt; TRUE,
    );
    return $items;
}


Additional resources


https://www.drupal.org/docs/7/administering-drupal-7-site/working-with-contextual-links
http://dominiquedecooman.com/blog/drupal-7-tip-add-contextual-links-anything