How to add a help tab to all admin pages – including plugin pages

This is how you can add help tabs to all admin pages—no matter if there already are any, or not:

add_action('in_admin_header', 'wpse_124979_add_help_tabs');

function wpse_124979_add_help_tabs() {
    if ($screen = get_current_screen()) {
        $help_tabs = $screen->get_help_tabs();
        $screen->remove_help_tabs();

        $screen->add_help_tab(array(
            'id' => 'my_help_tab',
            'title' => 'My Help',
            'content' => '<p>My help content...</p>',
        ));

        if (count($help_tabs))
            foreach ($help_tabs as $help_tab)
                $screen->add_help_tab($help_tab);
    }
} // function wpse_124979_add_help_tabs

In your OOP setting this should look something like the following:

// This could go in your constructor, for instance
add_action('in_admin_header', array($this, 'add_help_tabs'));

function add_help_tabs() {
    if ($screen = get_current_screen()) {
        $help_tabs = $screen->get_help_tabs();
        $screen->remove_help_tabs();

        foreach ($this->help_tabs as $id => $data)
            $screen->add_help_tab(array(
                'id' => $id,
                'title' => __($data['title'], 'q_support'),
                'callback' => array($this, 'callback_function'),
            ));

        if (count($help_tabs))
            foreach ($help_tabs as $help_tab)
                $screen->add_help_tab($help_tab);
    }
} // function add_help_tabs

in_admin_header is pretty much the last action hook before the screen meta (and so the help) is being rendered.

So, what do you get from this?

  • Add help tabs to every single Admin page (core, plugin, other);
  • your tabs will come before/on top of the original help tabs (if there are any);
  • even if there are no help tabs at all, your tabs will be added to the screen meta.

Leave a Comment

tech