Skip to content

Instantly share code, notes, and snippets.

@davidsword
Last active May 18, 2018 17:36
Show Gist options
  • Save davidsword/63de47ade3c1ea8bd4c12d8bd89dc67d to your computer and use it in GitHub Desktop.
Save davidsword/63de47ade3c1ea8bd4c12d8bd89dc67d to your computer and use it in GitHub Desktop.
show a custom message/notice after a NEW WordPress post has been published.
<?php
add_action('admin_notices', function(){
$screen = get_current_screen();
$editPostScreen = ($screen->parent_base == 'edit' && $screen->post_type == 'post') ? true : false;
$justPublished = (isset($_GET['message']) && $_GET['message'] == '6') ? true : false;
if ($editPostScreen && $justPublished) {
$class = 'notice notice-info';
$message = __( 'Just published a post custom text', 'myplugin_textdomain' );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
}
});
// ($justPublished relies on $_GET['message']. This URL query variable is not visible in admin address
// bar as Wordpress actually removes it from the URL with Javascript! Took me a long while to figure
// that out, so although you can't see it, it actually exists!).
add_filter( 'post_updated_messages', function($messages){
$messages['post'][6] = __( 'Just published a post custom text', 'myplugin_textdomain' );
return $messages;
}, 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment