WordPress at Your Fingertips

Hooks on Edit Post Admin Page

There are hooks that allow you to display any content in a particular place on the admin page of adding or editing any type of post.

Thanks to hooks below, you can make the publication more convenient. All depends on your programming skills and imagination. For example:

  • Place video or text right before the visual editor with tips on writing content.
  • Show images already attached to the post as a slider.
  • Show photos from Google by keyword so you can choose one of them for a thumbnail.
  • Display a calculator for counting calories, if you publish a recipe post.
  • And much more that require your certain task and allow programming skills.

This article describes the hooks on which you can display any content. In addition to these hooks, there are metaboxes that also help to extend the capabilities of the post editing page.

Hooks map

A visual representation of where and what kind of hook is used.

List of hooks sorted by location (top to down, right to left) (names are clickable):

edit_form_top
Fires before the field to enter the title of the post.
edit_form_before_permalink
Fires after the field to enter the title of the post, but before the link to the post.
edit_form_after_title
Fires after the field to enter the title of the post and a permanent link to it.
edit_form_after_editor
Fires after visual editor.
submitpage_box (for pages)
submitpost_box (for other post types)
Fires in the sidebar before the output of Metaboxs.
edit_page_form (for pages)
edit_form_advanced (for other post types)
Fires after all wide-column Metaboxs.
dbx_post_sidebar
Fires after all wide-column Metaboxs and all hooks. This is the last hook on the page

Example code with all hooks

By inserting this code in functions.php theme or active plugin file, you will get the result that is shown in the screenshot at the beginning of this article.

<?php
// Before the field to enter the title of the post
add_action( 'edit_form_top', 'callback__edit_form_top' );
function callback__edit_form_top( $post ) {
	?>
	<div style="margin-top: 10px;padding: 15px;color: #fff;background: #673AB7;clear: both;">
		Place of the hook <b>edit_form_top</b>.
	</div>
	<?php
}
<?php
// After the field to enter the title of the post, but before the link to the post
add_action( 'edit_form_before_permalink', 'callback__edit_form_before_permalink' );
function callback__edit_form_before_permalink( $post ) {
	?>
	<div style="margin-top: 10px;padding: 15px;color: #fff;background: #914029;clear: both;">
		Place of the hook <b>edit_form_before_permalink</b>.
	</div>
	<?php
}
<?php
// After the field to enter post title and the permalink to post
add_action( 'edit_form_after_title', 'callback__edit_form_after_title' );
function callback__edit_form_after_title( $post ) {
	?>
	<div style="margin-top: 10px;padding: 15px;color: #fff;background: #9876aa;clear: both;">
		Place of the hook <b>edit_form_after_title</b>.
	</div>
	<?php
}
<?php
// After the visual editor
add_action( 'edit_form_after_editor', 'callback__edit_form_after_editor' );
function callback__edit_form_after_editor( $post ) {
	?>
	<div style="margin-top: 10px;padding: 15px;color: #fff;background: #ff2401;clear: both;">
		Place of the hook <b>edit_form_after_editor</b>.
	</div>
	<?php
}
<?php
// Sidebar - before Metaboxs - Pages
add_action( 'submitpage_box', 'callback__submitpage_box' );
function callback__submitpage_box( $post ) {
	?>
	<div style="margin-top: 10px;padding: 15px;color: #fff;background: #8BC34A;clear: both;">
		Place of the hook <b>submitpage_box</b>.
	</div>
	<?php
}
<?php
// Sidebar - before Metaboxs - any post type except page
add_action( 'submitpost_box', 'callback__submitpost_box' );
function callback__submitpost_box( $post ) {
	?>
	<div style="margin-top: 10px;padding: 15px;color: #fff;background: #8BC34A;clear: both;">
		Place of the hook <b>submitpost_box</b>.
	</div>
	<?php
}
<?php
// After all Metabox of wide-column and only for pages
add_action( 'edit_page_form', 'callback__edit_page_form' );
function callback__edit_page_form( $post ) {
	?>
	<div style="margin-top: 10px;padding: 15px;color: #fff;background: #0085ba;clear: both;">
		Place of the hook <b>edit_page_form</b>.
	</div>
	<?php
}
<?php
// After all Metabox of wide-column, for any post type except page
add_action( 'edit_form_advanced', 'callback__edit_form_advanced' );
function callback__edit_form_advanced( $post ) {
	?>
	<div style="margin-top: 10px;padding: 15px;color: #fff;background: #795548;clear: both;">
		Place of the hook <b>edit_form_advanced</b>.
	</div>
	<?php
}
<?php
// After all Metabox of wide-column and hooks. This is the last hook on the page.
add_action( 'dbx_post_sidebar', 'callback__dbx_post_sidebar' );
function callback__dbx_post_sidebar( $post ) {
	?>
	<div style="margin-top: 10px;padding: 15px;color: #fff;background: #ff9800;clear: both;">
		Place of the hook <b>dbx_post_sidebar</b>.
	</div>
	<?php
}
4 comments
    Log In