Using WordPress ‘edit_form_after_title’ PHP action

The edit_form_after_title WordPress PHP action fires after the title field in the post editor, allowing you to add custom content or functionality.

Usage

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

Parameters

  • $post (WP_Post) – The WordPress post object for the current post being edited.

More information

See WordPress Developer Resources: edit_form_after_title

Examples

Add a custom text field below the title

This code adds a custom text field below the title field in the post editor.

add_action('edit_form_after_title', 'add_custom_text_field');
function add_custom_text_field($post) {
  // Get the custom field value
  $custom_text = get_post_meta($post->ID, '_custom_text', true);

  // Display the custom text field
  echo '<input type="text" name="custom_text" value="' . esc_attr($custom_text) . '" placeholder="Enter custom text...">';
}

Display a notice after the title

This code displays a notice with custom content after the title field in the post editor.

add_action('edit_form_after_title', 'display_notice_after_title');
function display_notice_after_title($post) {
  // Display the notice
  echo '<p style="color: red;">Remember to add a featured image before publishing!</p>';
}

Add a category dropdown menu

This code adds a category dropdown menu after the title field in the post editor.

add_action('edit_form_after_title', 'add_category_dropdown');
function add_category_dropdown($post) {
  // Get the categories
  $categories = get_categories();

  // Display the category dropdown menu
  echo '<select name="custom_category">';
  foreach ($categories as $category) {
    echo '<option value="' . $category->term_id . '">' . $category->name . '</option>';
  }
  echo '</select>';
}

Add a custom metabox after the title

This code adds a custom metabox after the title field in the post editor.

add_action('edit_form_after_title', 'add_custom_metabox');
function add_custom_metabox($post) {
  // Display the custom metabox
  echo '<div class="postbox">';
  echo '<h3 class="hndle">Custom Metabox</h3>';
  echo '<div class="inside">This is a custom metabox.</div>';
  echo '</div>';
}

This code displays the featured image thumbnail after the title field in the post editor.

add_action('edit_form_after_title', 'display_featured_image_thumbnail');
function display_featured_image_thumbnail($post) {
  // Get the featured image
  $thumbnail_id = get_post_thumbnail_id($post->ID);
  if ($thumbnail_id) {
    $thumbnail = wp_get_attachment_image($thumbnail_id, 'thumbnail');
    // Display the featured image thumbnail
    echo '<div>Featured Image:</div>';
    echo $thumbnail;
  }
}