Help!

Using WordPress help text

Simon Pollard

Full Time Web Developer at 

 

 

 

@smp303

 

https://slides.com/simonp303

What help text?

 

@smp303

In wp-admin in the top right

It is there for every screen

Click it...

@smp303

Defaults to the standard WordPress help

Tabs on left change content

You can add your own tabs!

@smp303

No need for user guides

Help directly relates to the current screen

Easily display short tags etc

The code...

@smp303

function pages_help() {

    global $post_ID;
    $screen = get_current_screen();

    if( isset($_GET['post_type']) ) $post_type = $_GET['post_type'];
    else $post_type = get_post_type( $post_ID );

    if( $post_type == 'page' ) :
        $content = '<h3>Title</h3>';
        $content .= '<p>Some text can go in here</p>';
        $screen->add_help_tab( array(
          'id' => 'help_tab_id', // unique id for the tab
          'title' => 'Tab Name', // unique visible title for the tab
          'content' => $content //actual help text
        ));
    endif;
    
}
add_action('admin_head', 'pages_help');

The code...

@smp303

function pages_help() {
    
}
add_action('admin_head', 'pages_help');

Create a function to handle our help text

Hook this function into the "admin_head" function

This makes sure our help text is displayed

Create our function

The code...

@smp303

global $post_ID;
$screen = get_current_screen();

if( isset($_GET['post_type']) ) $post_type = $_GET['post_type'];
else $post_type = get_post_type( $post_ID );

if( $post_type == 'page' ) :

endif;

Find out what screen we are on

Get the post type

If the conditions are correct - show our text

Display the help in the correct place

The code...

@smp303

$content = '<h3>Title</h3>';
$content .= '<p>Some text can go in here</p>';
$screen->add_help_tab( array(
    'id' => 'help_tab_id', // unique id for the tab
    'title' => 'Tab Name', // unique visible title for the tab
    'content' => $content //actual help text
));

Create some content

Call function (on the current screen) to show tab

Fill in all the attributes

Adding a help tab

Some more examples...

@smp303

aka Things will probably break

Resources

@smp303

These slides and more from me...
https://slides.com/simonp303

 

WordPress Codex
https://codex.wordpress.org/Class_Reference/WP_Screen/add_help_tab
 

Help!

By Simon Pollard

Help!

Using WordPress help text

  • 1,104