Skip to content

Instantly share code, notes, and snippets.

@phillip-boombox
Last active December 12, 2017 21:50
Show Gist options
  • Save phillip-boombox/73beb119539eb9681b502e4733200cd5 to your computer and use it in GitHub Desktop.
Save phillip-boombox/73beb119539eb9681b502e4733200cd5 to your computer and use it in GitHub Desktop.
WordPress: Add a help tab to an admin screen.
<?php
/**
* Add a help tab to the new/edit post screen.
* Action: admin_head-post.php, admin_head-post-new.php
*/
function cmfy_add_gumbo_help_tab() {
// Get the WP_Screen object
$screen = get_current_screen();
// Adjust / remove this conditional depending on which hook you're firing on
if ( 'comm_cpt_gumbo_ingr' == $screen->post_type ) {
$screen->add_help_tab( array(
'id' => 'gumbo-info',
'title' => __( 'Usage', 'cmfy' ),
'content' =>
'<p>' . esc_html__( 'This post type will create a gumbo ingredient entry which is a small thumbnail with some hover information.', 'cmfy' ) . '</p>' .
'<ul>' .
'<li>' . __( '<strong>Title</strong> will show up when an icon is hovered over.', 'cmfy' ) . '</li>' .
'<li>' . __( '<strong>Excerpt</strong> is currently not used on the front-end but is kept in place for a future addition.', 'cmfy' ) . '</li>' .
'</ul>'
) );
$screen->set_help_sidebar( __( '<p><strong>For more information:</strong></p><p><a href="/gumbo">View Gumbo</a></p>', 'cmfy' ) );
}
}
/**
* Change actions depending on which screen you want the help tabs.
* In this case, I want this help tab to fire on new / update post type.
* I am restricing which post type with a conditional post type lookup inside of
* the callback. For example, if you wanted to add a help tab to the
* general options page, hook into 'admin_head-options-general.php'.
*/
add_action( 'admin_head-post.php', 'cmfy_add_gumbo_help_tab' );
add_action( 'admin_head-post-new.php', 'cmfy_add_gumbo_help_tab' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment