Using WordPress ‘edit_page_form’ PHP action

The edit_page_form WordPress action allows you to execute custom code after the ‘normal’ context meta boxes have been output for the ‘page’ post type.

Usage

add_action('edit_page_form', 'your_custom_function');

function your_custom_function($post) {
  // your custom code here
}

Parameters

  • $post (WP_Post): The post object for the page being edited.

More information

See WordPress Developer Resources: edit_page_form

Examples

Add a Custom Field to the Page Edit Screen

This example adds a custom field to the page edit screen below the meta boxes.

add_action('edit_page_form', 'add_custom_field');

function add_custom_field($post) {
  $custom_value = get_post_meta($post->ID, 'custom_value', true);
  echo '<label for="custom_value">Custom Value:</label>';
  echo '<input type="text" name="custom_value" id="custom_value" value="' . esc_attr($custom_value) . '">';
}

Display a Custom Message Below Meta Boxes

This example displays a custom message below the meta boxes on the page edit screen.

add_action('edit_page_form', 'display_custom_message');

function display_custom_message($post) {
  echo '<p><strong>Important:</strong> Please double-check all details before publishing.</p>';
}

Add a Custom CSS Class to the Page Edit Screen

This example adds a custom CSS class to the page edit screen based on a custom field value.

add_action('edit_page_form', 'add_custom_css_class');

function add_custom_css_class($post) {
  $custom_css_class = get_post_meta($post->ID, 'custom_css_class', true);
  echo '<style>.postbox { border-color: ' . esc_attr($custom_css_class) . '; }</style>';
}

Display a Custom Reminder Based on Page Template

This example displays a custom reminder based on the selected page template.

add_action('edit_page_form', 'display_custom_reminder');

function display_custom_reminder($post) {
  $page_template = get_post_meta($post->ID, '_wp_page_template', true);

  if ($page_template == 'template-contact.php') {
    echo '<p><strong>Reminder:</strong> Don\'t forget to set up the contact form settings.</p>';
  }
}