Using WordPress ‘post_submitbox_start’ PHP action

The post_submitbox_start WordPress PHP action fires at the beginning of the publishing actions section of the Publish meta box.

Usage

add_action('post_submitbox_start', 'your_custom_function', 10, 1);

function your_custom_function($post) {
    // your custom code here
}

Parameters

  • $post (WP_Post|null) – WP_Post object for the current post on the Edit Post screen, null on the Edit Link screen.

More information

See WordPress Developer Resources: post_submitbox_start

Examples

Add a custom message at the start of the Publish meta box

This example adds a custom message at the start of the Publish meta box.

add_action('post_submitbox_start', 'add_custom_message', 10, 1);

function add_custom_message($post) {
    echo '<p><strong>Reminder:</strong> Please proofread your post before publishing.</p>';
}

Display current post’s word count

This example displays the current post’s word count in the Publish meta box.

add_action('post_submitbox_start', 'display_word_count', 10, 1);

function display_word_count($post) {
    $content = $post->post_content;
    $word_count = str_word_count(strip_tags($content));
    echo '<p>Word count: ' . $word_count . '</p>';
}

Show the number of attached images

This example shows the number of attached images in the Publish meta box.

add_action('post_submitbox_start', 'show_attached_images_count', 10, 1);

function show_attached_images_count($post) {
    $attachments = get_attached_media('image', $post->ID);
    $count = count($attachments);
    echo '<p>Attached images: ' . $count . '</p>';
}

Display a warning for posts in a specific category

This example displays a warning for posts in a specific category (e.g. “Announcements”).

add_action('post_submitbox_start', 'display_category_warning', 10, 1);

function display_category_warning($post) {
    if (has_category('announcements', $post)) {
        echo '<p><strong>Warning:</strong> This post is in the "Announcements" category. Double-check before publishing.</p>';
    }
}

Show a custom message depending on post status

This example shows a custom message depending on the current post status.

add_action('post_submitbox_start', 'display_post_status_message', 10, 1);

function display_post_status_message($post) {
    $status = $post->post_status;

    if ($status === 'draft') {
        echo '<p><strong>Note:</strong> This post is currently a draft.</p>';
    } elseif ($status === 'pending') {
        echo '<p><strong>Note:</strong> This post is pending review.</p>';
    } elseif ($status === 'publish') {
        echo '<p><strong>Note:</strong> This post is already published.</p>';
    }
}