How to show an error message after publishing a post?

I wouldn’t use that hook. Here’s why

Try something like this using admin_notices.

function wpsites_admin_notice() {
$screen = get_current_screen();
if( 'post' == $screen->post_type
&& 'edit' == $screen->base ){
?>
<div class="error">
    <p><?php _e( 'Updated Demo Message!', 'wpsites' ); ?></p>
</div>
<?php
}}
add_action( 'admin_notices', 'wpsites_admin_notice' );

Untested.

Leave a Comment