post_updated_messages

Home » Hooks » post_updated_messages

The post_updated_messages hook is a WordPress filter that allows developers to modify the messages displayed when a post or page is updated.

Every time a user updates a post or page, WordPress displays a message confirming the update. These messages include success messages, error messages, and warning messages. The post_updated_messages hook provides developers with the ability to customize these messages to fit their specific needs.

The hook takes an array of messages as an argument and returns a modified version of that array. Developers can modify the text displayed in these messages, change the order in which they appear, or even add new messages altogether.

For example, let’s say that you want to add a new message to be displayed when a post is updated. You can use the post_updated_messages filter to add this new message to the array of messages that WordPress displays. Here’s an example usage code:

function custom_updated_messages( $messages ) {
    $messages['post']['updated'] .= ' My custom message';
    return $messages;
}
add_filter( 'post_updated_messages', 'custom_updated_messages' );

In this example, we’re using the post_updated_messages filter to add the text " My custom message" to the end of the default "Post updated" message. When a user updates a post, they’ll now see the updated message with our custom message added to the end.

Learn More on WordPress.org

WordPress snippets using the post_updated_messages hook

Register an account to save your snippets or go Pro to get more features.