wp code snippet

WordPress, PHP quick help codes

Customizing WordPress Admin: Adding content before Title, after Title, after Editor and after Excerpt

Sometimes we need to made customizations on the screen as per our specific requirements. The meatbox area gives us more fixability but what if we need some more customisations like before title, after title, after editor and after excerpt.

Here are some actions that let you hook onto above mentions area.

  • edit_form_top: Runs inside the form before the title on WordPress post edit screen (and Custom Post Types), but after the inital hidden fields (user_ID, action, etc.).
  • edit_form_after_title: Runs after the title on WordPress post edit screen (and Custom Post Types) but before the built in WordPress content area.
  • edit_form_after_editor: Runs just after the WordPress post editor but before all other meta boxes. also available in Custom Post Types.
  • edit_form_advanced: Runs just before the “advanced” section of the post editing form in the admin menus.

Copy and paste (in functions.php) below codes to get output.

function ps_edit_form_top() {
echo '<h2>edit_form_top</h2>';
}
add_action( 'edit_form_top', 'ps_edit_form_top');

function ps_edit_form_after_title() {
echo '<h2>edit_form_after_title</h2>';
}
add_action( 'edit_form_after_title', 'ps_edit_form_after_title');

function ps_edit_form_after_editor() {
echo '<h2>edit_form_after_editor</h2>';
}
add_action( ‘edit_form_after_editor', 'ps_edit_form_after_editor' );

function ps_edit_form_advanced() {
echo '<h2>edit_form_advanced</h2>';
}
add_action( 'edit_form_advanced', ‘ps_edit_form_advanced' );

// If you want this content appears only on selected post_type, go through below codes:
function ps_edit_form_top( $post_type ) {
$screen = get_current_screen();
$post_type = $screen->post_type;
if ( $post_type != 'post' )
return;

echo '<h2>edit_form_top</h2>';

}
add_action( 'edit_form_top', ‘ps_edit_form_top' );

Reference Source:

Categories: Uncategorized

Leave a Reply

%d bloggers like this: