The edit_form_before_permalink WordPress action fires before the permalink field in the edit form and allows you to modify the edit form content.
Usage
add_action('edit_form_before_permalink', 'your_custom_function', 10, 1); function your_custom_function($post) { // your custom code here }
Parameters
$post
(WP_Post) – The post object.
More information
See WordPress Developer Resources: edit_form_before_permalink
Examples
Add a Custom Text Field
Add a custom text field before the permalink field.
add_action('edit_form_before_permalink', 'add_custom_text_field', 10, 1); function add_custom_text_field($post) { echo '<input type="text" name="custom_field" value="' . esc_attr(get_post_meta($post->ID, 'custom_field', true)) . '">'; }
Display Post ID
Display the post ID before the permalink field.
add_action('edit_form_before_permalink', 'display_post_id', 10, 1); function display_post_id($post) { echo 'Post ID: ' . $post->ID; }
Add a Custom Message
Add a custom message before the permalink field.
add_action('edit_form_before_permalink', 'add_custom_message', 10, 1); function add_custom_message($post) { echo 'Remember to optimize your permalink for SEO!'; }
Display Post Type
Display the post type before the permalink field.
add_action('edit_form_before_permalink', 'display_post_type', 10, 1); function display_post_type($post) { echo 'Post Type: ' . $post->post_type; }
Add a Custom Dropdown
Add a custom dropdown before the permalink field.
add_action('edit_form_before_permalink', 'add_custom_dropdown', 10, 1); function add_custom_dropdown($post) { $selected_value = get_post_meta($post->ID, 'custom_dropdown', true); echo '<select name="custom_dropdown">'; echo '<option value="option1"' . selected($selected_value, 'option1', false) . '>Option 1</option>'; echo '<option value="option2"' . selected($selected_value, 'option2', false) . '>Option 2</option>'; echo '</select>'; }