Using WordPress ‘post_submitbox_minor_actions’ PHP action

The post_submitbox_minor_actions WordPress PHP action fires after the Save Draft (or Save as Pending) and Preview (or Preview Changes) buttons in the Publish meta box. It can be used to add custom buttons or elements in the Publish meta box.

Usage

add_action('post_submitbox_minor_actions', 'your_custom_function');
function your_custom_function($post) {
  // your custom code here
}

Parameters

  • $post (WP_Post): WP_Post object for the current post.

More information

See WordPress Developer Resources: post_submitbox_minor_actions

Examples

Add a custom button to the Publish meta box

Add a new button named “Custom Action” below the Preview button.

add_action('post_submitbox_minor_actions', 'add_custom_button');
function add_custom_button($post) {
  echo '<div id="custom-action" class="misc-pub-section">';
  echo '  <input type="submit" name="custom_action" value="Custom Action" class="button" />';
  echo '</div>';
}

Display word count in the Publish meta box

Display the word count of the post content below the Save Draft button.

add_action('post_submitbox_minor_actions', 'display_word_count');
function display_word_count($post) {
  $word_count = str_word_count($post->post_content);
  echo '<div class="misc-pub-section misc-pub-word-count">';
  echo '  Word count: <b>' . $word_count . '</b>';
  echo '</div>';
}

Add custom checkbox to the Publish meta box

Add a custom checkbox named “Special Post” below the Preview button.

add_action('post_submitbox_minor_actions', 'add_special_post_checkbox');
function add_special_post_checkbox($post) {
  echo '<div class="misc-pub-section misc-pub-special-post">';
  echo '  <label><input type="checkbox" name="special_post" value="1" /> Special Post</label>';
  echo '</div>';
}

Display post ID in the Publish meta box

Display the ID of the current post below the Save Draft button.

add_action('post_submitbox_minor_actions', 'display_post_id');
function display_post_id($post) {
  echo '<div class="misc-pub-section misc-pub-post-id">';
  echo '  Post ID: <b>' . $post->ID . '</b>';
  echo '</div>';
}

Add a custom message to the Publish meta box

Add a custom message below the Save Draft button, based on the post status.

add_action('post_submitbox_minor_actions', 'add_custom_message');
function add_custom_message($post) {
  $message = '';
  if ($post->post_status == 'draft') {
    $message = 'This is a draft post.';
  } elseif ($post->post_status == 'publish') {
    $message = 'This post is published.';
  }
  echo '<div class="misc-pub-section misc-pub-custom-message">';
  echo '  <span>' . $message . '</span>';
  echo '</div>';
}