post_updated_messages is a WordPress PHP filter that allows you to modify the messages displayed after a post is updated.
Usage
add_filter('post_updated_messages', 'your_custom_function'); function your_custom_function($messages) { // your custom code here return $messages; }
Parameters
- $messages (array): An array containing the default post updated messages. You can modify these messages as needed.
Default messages:
For Posts:
$messages[‘post’]
0
: Unused. Messages start at index 1.1
: Post updated.2
: Custom field updated.3
: Custom field deleted.4
: Post updated.5
: Post restored to revision from {revision date and time}.6
: Post published.7
: Post saved.8
: Post submitted.9
: Post scheduled for: {scheduled date}.10
: Post draft updated.
For Pages:
$messages[‘page’]
0
: Unused. Messages start at index 1.1
: Page updated.2
: Custom field updated.3
: Custom field deleted.4
: Page updated.5
: Page restored to revision from {revision date and time}.6
: Page published.7
: Page saved.8
: Page submitted.9
: Page scheduled for: {scheduled date}.10
: Page draft updated.
For Attachments:
$messages[‘attachment’]
- Messages 1 to 10: Media file updated.
More information
See WordPress Developer Resources: post_updated_messages
Examples
Customize the ‘Post Published’ Message
Change the ‘Post published’ message to include a custom thank you note.
add_filter('post_updated_messages', 'custom_post_published_message'); function custom_post_published_message($messages) { $messages['post'][6] = 'Post published. Thank you for contributing!'; return $messages; }
Add Emojis to Update Messages
Add a checkmark emoji to the ‘Post updated’ message.
add_filter('post_updated_messages', 'add_emoji_to_update_message'); function add_emoji_to_update_message($messages) { $messages['post'][1] = '✅ Post updated.'; return $messages; }
Customize Messages for Custom Post Types
Change the ‘Post updated’ message for a custom post type called ‘Event’.
add_filter('post_updated_messages', 'custom_event_update_message'); function custom_event_update_message($messages) { $messages['event'][1] = 'Event updated successfully.'; return $messages; }
Remove the ‘Post scheduled’ Message
Remove the ‘Post scheduled’ message by setting it to an empty string.
add_filter('post_updated_messages', 'remove_post_scheduled_message'); function remove_post_scheduled_message($messages) { $messages['post'][9] = ''; return $messages; }
Add a Custom Message for Draft Posts
Add a custom message when saving a post as a draft.
add_filter('post_updated_messages', 'custom_draft_post_message'); function custom_draft_post_message($messages) { $messages['post'][10] = 'Your draft has been saved. Keep up the good work!'; return $messages; }