0

I want show my own (2) admin_notices after a post is published.

How can i do this ?

P.s: I need this to show results of my external function.

Thanks.

0

Add Additional 'Published' Notices

You can use the following to add an additional admin notice after a post has been published:

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!).


Edit The Default 'Published' Notice

You can use the following to edit the admin notice after a post has been published:

add_filter( 'post_updated_messages', function($messages){
    $messages['post'][6] = __( 'Just published a post custom text', 'myplugin_textdomain' );
    return $messages;
}, 10, 1 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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