Using the new WP_Screen
class makes it pretty easy to add help text to a screen.
<?php
add_action( "load-{$somepage}", 'wpse_load_reading' );
function wpse_load_reading()
{
get_current_screen()->add_help_tab( array(
'id' => 'my-help-tab',
'title' => __( 'My Title' ),
'content' => __( 'Help Content' )
) );
}
This is great for custom pages. But when adding a help tab to an existing screen, let’s say options-reading.php
, some weirdness happens.
The load-options-reading.php
hook fires before the built in WP page adds its own help tabs. In other words, adding a help tab to an existing screen bumps all the built in help tabs to the bottom of the of list.
Here’s some code, if you’d like to try this out:
<?php
add_action( "load-options-reading.php", 'wpse_load_reading2' );
function wpse_load_reading2()
{
get_current_screen()->add_help_tab( array(
'id' => 'my-help-tab',
'title' => __( 'My Title' ),
'content' => __( 'Why is this tab above the built in tab?' )
) );
}
Is there any way to reorder the help tabs on a screen?
EDIT:
Found a way around this. The default help tabs are added before the admin-header.php
file is included.
So you can hook into load-{$built_in_page}
, and from there hook a function admin_head
which takes care of setting up your help tabs.
<?php
add_action( 'load-options-reading.php', 'wpse45210_load' );
function wpse45210_load()
{
add_action( 'admin_head', 'wpse45210_add_help' );
}
function wpse45210_add_help()
{
get_current_screen()->add_help_tab( array(
'id' => 'my-help-tab',
'title' => __( 'My Title' ),
'content' => __( 'This tab is below the built in tab.' )
) );
}
Seems kind of like a hack. Is there a better way?
Use
admin_head-$hook_suffix
action, this is same method just removes exta action and callback.As @Mamaduka suggested, you can hook into
admin_head-{$page_hook}
and add the contextual help there.admin_head
fires after the default contextual help tabs have been added.I guess you have three chances:
WP_Screen->$_help_tabs
to reorder them manually.WP_Screen->remove_help_tab( $id )
and then add them back in manually.admin_head
filter to populate the help tabs or missuse one of the filters or hooks that fire before it in admin-header.php