The edit_form_after_title
hook is a WordPress action hook that is triggered after the main title field on the edit post or page screen, but before the main editor content field. It is typically used to add custom content or fields to the top of the editing screen.
For example, if you have a custom post type for books, you could use edit_form_after_title
to add a custom text field for the book’s ISBN number. This would allow you to easily track and display the ISBN for each book in your database.
Here’s an example usage code:
add_action( 'edit_form_after_title', 'add_book_isbn_field' );
function add_book_isbn_field( $post ) {
// Add a custom field for the book's ISBN number
echo '<div class="isbn-field"><label for="isbn">ISBN:</label> <input type="text" name="isbn" value="' . esc_attr( get_post_meta( $post->ID, 'isbn', true ) ) . '" /></div>';
}
In this example, we’re using the add_action
function to add a callback function named add_book_isbn_field
to the edit_form_after_title
hook. This function takes a $post
object as a parameter, which we can use to get the current post’s ID and any existing ISBN meta data.
The function then outputs a custom HTML field for the ISBN, including a label and an input field with the current meta data pre-populated using the get_post_meta
function.
Overall, edit_form_after_title
is a useful hook for customizing the WordPress editing screen and adding additional content or fields to your posts and pages.