Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

Use admin_head-$hook_suffix action, this is same method just removes exta action and callback.

share|improve this answer
    
Good call. This is probably the best solution. –  chrisguitarguy Mar 11 '12 at 21:23
    
@ChristopherDavis Maybe you want to move your edit to an answer and mark it as solution. Mamaduka gets an upvote in exchange from me. :) –  kaiser Mar 11 '12 at 23:15
    
Done and done. Just need to wait two days to accept. –  chrisguitarguy Mar 12 '12 at 0:38
add comment
up vote 2 down vote accepted

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.

<?php
add_action( 'admin_head-options-reading.php', '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.' )
    ) );
}
share|improve this answer
add comment

I guess you have three chances:

  1. Use WP_Screen->$_help_tabs to reorder them manually.
  2. Grap the existing help tabs, save them temporarily somewhere else. Then use WP_Screen->remove_help_tab( $id ) and then add them back in manually.
  3. Use the admin_head filter to populate the help tabs or missuse one of the filters or hooks that fire before it in admin-header.php
share|improve this answer
1  
WP_Screen::$_help_tabs is private. Can't access it directly, unfortunately. See my edit, I did your third suggestion! –  chrisguitarguy Mar 11 '12 at 18:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.