Contextual links for programmatically embedded views When embedding a View programmatically, using views_embed_view, what can I do to have the contextual menu (gear icon) appear over its area?
Views does this by wrapping the render array output with the views_add_block_contextual_links() function. It checks if the display plugin has contextual links associated with it. If the $display_id is a block then it will have the contextual links.

  if ($view = views_get_view($name)) {
    if ($view-&gt;access($display_id)) {
      $output = $view-&gt;execute_display($display_id);
      // Before returning the block output, convert it to a renderable array
      // with contextual links.
      views_add_block_contextual_links($output, $view, $display_id);
      $view-&gt;destroy();
      return $output;
    }
    $view-&gt;destroy();
  }


You already understand the $name and $display_id. The output from this needs the render() function. You can put this in a function that is called in TEMPLATE_preprocess_node(), for example, and then use print render($embedded_view) in the node.tpl.php template.