The post_submitbox_misc_actions WordPress PHP action fires after the post time/date setting in the Publish meta box.
Usage
add_action('post_submitbox_misc_actions', 'your_custom_function_name');
function your_custom_function_name($post) {
// your custom code here
}
Parameters
$post(WP_Post) – WP_Post object for the current post.
More information
See WordPress Developer Resources: post_submitbox_misc_actions
Examples
Add a custom meta box field
Add a custom field to the Publish meta box.
add_action('post_submitbox_misc_actions', 'add_custom_meta_box_field');
function add_custom_meta_box_field($post) {
// Get current value of custom field
$custom_field_value = get_post_meta($post->ID, 'your_custom_field', true);
// Display the custom field in the Publish meta box
echo '<div class="misc-pub-section"><label for="your_custom_field">Custom Field: </label><input type="text" name="your_custom_field" id="your_custom_field" value="' . esc_attr($custom_field_value) . '" /></div>';
}
Display a warning message based on post status
Display a warning message in the Publish meta box if the post status is “draft”.
add_action('post_submitbox_misc_actions', 'display_warning_message');
function display_warning_message($post) {
if ($post->post_status === 'draft') {
echo '<div class="misc-pub-section misc-pub-warning">Please review your content before publishing!</div>';
}
}
Change the background color of Publish meta box based on post status
Change the background color of the Publish meta box according to the post status.
add_action('post_submitbox_misc_actions', 'change_publish_meta_box_color');
function change_publish_meta_box_color($post) {
$color = ($post->post_status === 'draft') ? '#FFC0CB' : '#90EE90';
echo '<style>.postbox { background-color: ' . esc_attr($color) . '; }</style>';
}
Add a custom CSS class to Publish meta box based on post status
Add a custom CSS class to the Publish meta box according to the post status.
add_action('post_submitbox_misc_actions', 'add_custom_css_class');
function add_custom_css_class($post) {
$custom_class = ($post->post_status === 'draft') ? 'custom-draft' : 'custom-published';
echo '<script>jQuery(document).ready(function($) { $(".postbox").addClass("' . esc_js($custom_class) . '"); });</script>';
}
Display the post’s word count
Display the word count of the post content in the Publish meta box.
add_action('post_submitbox_misc_actions', 'display_word_count');
function display_word_count($post) {
$word_count = str_word_count($post->post_content);
echo '<div class="misc-pub-section">Word count: <strong>' . intval($word_count) . '</strong></div>';
}