The edit_form_top WordPress action fires at the beginning of the edit form, after the required hidden fields and nonces have already been output.
Usage
add_action('edit_form_top', 'your_custom_function'); function your_custom_function($post) { // your custom code here }
Parameters
$post
(WP_Post): The post object being edited.
More information
See WordPress Developer Resources: edit_form_top
Examples
Add a custom message above the edit form
This example adds a custom message above the post edit form.
add_action('edit_form_top', 'add_custom_message'); function add_custom_message($post) { echo '<p><strong>Note:</strong> Please double-check all content before publishing.</p>'; }
Display the current post status
This example displays the current post status above the edit form.
add_action('edit_form_top', 'display_post_status'); function display_post_status($post) { echo '<p>Current post status: ' . $post->post_status . '</p>'; }
Show a warning for older posts
This example shows a warning message if the post is older than 365 days.
add_action('edit_form_top', 'warn_old_posts'); function warn_old_posts($post) { $post_age = (time() - strtotime($post->post_date)) / (60 * 60 * 24); if ($post_age > 365) { echo '<p><strong>Warning:</strong> This post is over a year old. Please update any outdated information.</p>'; } }
Display word count
This example displays the word count of the post content above the edit form.
add_action('edit_form_top', 'display_word_count'); function display_word_count($post) { $word_count = str_word_count(strip_tags($post->post_content)); echo '<p>Word count: ' . $word_count . '</p>'; }
Show a custom message for specific post type
This example adds a custom message above the edit form for a specific custom post type.
add_action('edit_form_top', 'custom_message_for_post_type'); function custom_message_for_post_type($post) { if ($post->post_type == 'your_custom_post_type') { echo '<p><strong>Reminder:</strong> Make sure to add a featured image for better presentation.</p>'; } }