add custom fields to the post on admin side

To insert your own custom field after the title field you will have to invoke the hook edit_form_after_title. You may at the following to your plugin or theme:

add_action('edit_form_after_title', function() {
  global $post;
  print '<input type="text" name="post_title" size="30" tabindex="1" value="'.esc_attr( htmlspecialchars( $post->post_title ) ).'" id="title" autocomplete="off" />';
});

Note: the default title field will stop working if you add this field (it won’t save anymore).

All default post attributes don’t necessarily require a form submit handler. Your field will use the default handlers what come with wordpress. However if you want to add custom fields which are not available yet or if you want to alter default behavior of the handlers then you will have to invoke the save_post hook as well.

I recommend specifying to the post type you want to hook on by appending the name to the hook (e.g. save_post_book). This hook enables you to apply logic to the form data submitted by the user.

Leave a Comment