How to customize post edit notices

How to customize the notice message (‘Post published’ or ‘Post updated’) displayed when I add or edit a custom post type registered with register_post_type() function?

2 Answers
2

You can used the post_updated_messages filter.

add_filter( 'post_updated_messages', 'rw_post_updated_messages' );


function rw_post_updated_messages( $messages ) {

$post             = get_post();
$post_type        = get_post_type( $post );
$post_type_object = get_post_type_object( $post_type );

$messages['my-post-type'] = array(
    0  => '', // Unused. Messages start at index 1.
    1  => __( 'My Post Type updated.' ),
    2  => __( 'Custom field updated.' ),
    3  => __( 'Custom field deleted.'),
    4  => __( 'My Post Type updated.' ),
    /* translators: %s: date and time of the revision */
    5  => isset( $_GET['revision'] ) ? sprintf( __( 'My Post Type restored to revision from %s' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
    6  => __( 'My Post Type published.' ),
    7  => __( 'My Post Type saved.' ),
    8  => __( 'My Post Type submitted.' ),
    9  => sprintf(
        __( 'My Post Type scheduled for: <strong>%1$s</strong>.' ),
        // translators: Publish box date format, see http://php.net/date
        date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) )
    ),
    10 => __( 'My Post Type draft updated.' )
);

    //you can also access items this way
    // $messages['post'][1] = "I just totally changed the Updated messages for standards posts";

    //return the new messaging 
return $messages;
}

Leave a Comment