Viewing 10 replies - 1 through 10 (of 10 total)
  • Add it to what page? A plugin page? A standard WordPress admin page?

    More details please.

    Thread Starter Alexandru Vornicescu

    (@alexvorn2)

    To a admin standard page. Thanks!

    Not sure you can add additional help to pages that already have help text (didn’t work for me), but for pages where none exists it should be fine.

    Example:

    add_action( 'admin_head-options.php', 'add_help_to_options' );
    function add_help_to_options() {
    	add_contextual_help( 'options.php', "TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />" );
    }

    In this case i’ve given the options.php page some help text. Ordinarily you don’t see this page, so to test the above you’ll need to visit wp-admin/options.php to see the help text under the help button (after adding the code of course).

    Importantly, you just need the page hook name for the page you want to hook onto, in the above example the page hook is options.php, and some other examples would be..

    edit.php - post management page
    options-general.php - options general page
    edit-tags.php - term/tag management page

    Again, like i said, i don’t believe you can add help if the given page already has help text, but i’d be happy for someone to prove me wrong on that one.

    Quick way to get the hook for the given page in the administration.

    function print_admin_hook_to_source() {
    	global $hook_suffix;
    	echo "<!-- The hook for the current page is \"";
    	print_r( $hook_suffix );
    	echo "\" -->\n";
    }
    add_action( 'admin_head', 'print_admin_hook_to_source' );

    Which would print the hook name into the source code of each admin page, just view source and look for the line “The hook for the current page is” …

    Hope that helps..

    Thread Starter Alexandru Vornicescu

    (@alexvorn2)

    I wanted to add a help page on my admin.php?page=my_settings page but with no success…

    tried:

    add_action( 'admin_head-admin.php?page=my_settings', 'add_help_to_options' );
    function add_help_to_options() {
    	add_contextual_help( 'admin.php?page=my_settings', "TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />" );
    }

    what I did wrong? or adding a help page here is impossible?

    Is the hook definately correct?

    The function i provided above print_admin_hook_to_source will print the hook into the source of the page, is admin.php?page=my_settings the name of the hook you see?

    Thread Starter Alexandru Vornicescu

    (@alexvorn2)

    ??
    no, the hook I got is toplevel_page_my_settings

    <!-- The hook for the current page is "toplevel_page_my_settings" -->

    what should I do next?

    Replace admin.php?page=my_settings with the hook you see toplevel_page_my_settings, ie..

    Here..

    add_action( 'admin_head-toplevel_page_my_settings', 'add_help_to_options' );

    and here..

    add_contextual_help( 'toplevel_page_my_settings', "TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />TEST<br />" );

    Thread Starter Alexandru Vornicescu

    (@alexvorn2)

    wow! Thanks! Respect! ??

    You’re welcome. ??

    Method for editing existing contextual help:

    /**
     * Modify contextual help
     * @since 0.1
     */
    function pixopoint_modify_contextual_help() {
    	global $_wp_contextual_help;
    	$_wp_contextual_help['dashboard'] = 'Woop woop! Ron\'s trick worked :)';
    }
    add_action( 'admin_head', 'pixopoint_modify_contextual_help' );

    Hat tip to Ron Rennick for point out the $_wp_contextual_help global that controls this.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘add_contextual_help’ is closed to new replies.