Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aaronsummers/0a027ab84f9e18be1876d3dc3ab4daf2 to your computer and use it in GitHub Desktop.
Save aaronsummers/0a027ab84f9e18be1876d3dc3ab4daf2 to your computer and use it in GitHub Desktop.
WordPress - Add custom admin notification to custom post type admin screen
<?php
function support_admin_notice() {
// https://codex.wordpress.org/Function_Reference/get_current_screen
$screen = get_current_screen();
// echo '<pre>' . var_export($screen, true) . '</pre>'; // View screen dump
//If not on the screen with post_type 'support' abort.
if( $screen->post_type !='support' )
return;
// If on the Add New screen
if( $screen->base == 'post' ) :
$message = 'Select the <strong>"Support Type"</strong> below the title to associate this post with the support item.';
// If on the All Items screen
elseif( $screen->base == 'edit') :
$message = '<p>The journey for the knowledgebase begins with the <a href="' . admin_url( 'edit-tags.php?taxonomy=support_type&post_type=knowledgebase' ) . '">"Support Type"</a> Categories. These are used to form the questions for the support page.</p>';
$message .= '<p>The suport types are hierarchical and are used to form the initial journey.</p>';
// If on the Support Type Taxonomy screen
// elseif( $screen->base == 'edit-tags' ) :
elseif( $screen->taxonomy == 'support_type' ) :
$message = '<p>Each <strong>"Support Type"</strong> requires a description, this forms the introductory question that appears above the choices.</p>';
$message .= '<p>ex.<br><strong>"Support Type"</strong> -> Account<br><strong>"Description"</strong> -> What’s happening with your account?</p>';
$message .= '<p>With the categories added we need to include the actual knowledge. <a href="'. admin_url( 'post-new.php?post_type=support' ) .'">"Add New"</p>';
endif;
echo '<div class="notice notice-info">'
. $message
.'</div>';
}
add_action('admin_notices','support_admin_notice');

There are four types of notice classes:

notice-error – error message displayed with a red border
notice-warning – warning message displayed with a yellow border
notice-success – success message displayed with a green border
notice-info – info message displayed with a blue border
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment