Using WordPress ‘add_contextual_help()’ PHP function

The add_contextual_help() WordPress PHP function is used to add contextual help text for a page. It essentially creates an ‘Overview’ help tab. However, it’s worth noting that this function is deprecated and is recommended to be replaced with the add_help_tab() function.

Usage

Here’s a basic example of how to use the add_help_tab() function:

$screen = get_current_screen();
$screen->add_help_tab( array(
    'id' => 'my_help_tab',
    'title' => 'My Help Tab',
    'content' => 'This is my custom help content.',
) );

In this case, my_help_tab is a unique id for the tab, My Help Tab is the visible title, and This is my custom help content. is the actual help text.

Parameters

  • $screen (string) – Required. The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions.
  • $help (string) – Required. The content of an ‘Overview’ help tab.

More information

See WordPress Developer Resources: add_contextual_help()

This function has been deprecated, so it’s advised to use the add_help_tab() function instead.

Examples

Adding a Basic Help Tab

$screen = get_current_screen();
$screen->add_help_tab( array(
    'id' => 'basic_help',
    'title' => 'Basic Help',
    'content' => 'This is a basic help tab.',
) );

This code adds a basic help tab with the id basic_help, title Basic Help, and content This is a basic help tab..

Adding Multiple Help Tabs

$screen = get_current_screen();

// First help tab
$screen->add_help_tab( array(
    'id' => 'first_help',
    'title' => 'First Help',
    'content' => 'This is the first help tab.',
) );

// Second help tab
$screen->add_help_tab( array(
    'id' => 'second_help',
    'title' => 'Second Help',
    'content' => 'This is the second help tab.',
) );

This code adds two help tabs to the screen.

Using HTML in Help Content

$screen = get_current_screen();
$screen->add_help_tab( array(
    'id' => 'html_help',
    'title' => 'HTML Help',
    'content' => '<p>This is a help tab with <strong>HTML</strong> content.</p>',
) );

This code adds a help tab with HTML content.

Adding a Help Sidebar

$screen = get_current_screen();
$screen->add_help_tab( array(
    'id' => 'help_sidebar',
    'title' => 'Help Sidebar',
    'content' => 'This is a help tab with a sidebar.',
) );
$screen->set_help_sidebar(
    '<p>This is the sidebar content.</p>'
);

This code adds a help tab and a sidebar with additional information.