/** | |
* Move the excerpt metabox to the top | |
* @param $post_type | |
*/ | |
function doublee_custom_excerpt_metabox( $post_type ) { | |
if(in_array($post_type, array('post','page'))) { | |
add_meta_box( | |
'excerpt_meta', __( 'Excerpt' ), 'post_excerpt_meta_box', $post_type, 'temp', 'high' | |
); | |
} | |
} | |
add_action( 'add_meta_boxes', 'doublee_custom_excerpt_metabox' ); | |
function doublee_run_custom_excerpt_meta_box() { | |
# Get the globals: | |
global $post, $wp_meta_boxes; | |
# Output the "advanced" meta boxes: | |
do_meta_boxes( get_current_screen(), 'temp', $post ); | |
} | |
add_action( 'edit_form_after_title', 'doublee_run_custom_excerpt_meta_box' ); | |
function doublee_remove_normal_excerpt() { | |
remove_meta_box( 'postexcerpt' , 'post' , 'normal' ); | |
remove_meta_box( 'postexcerpt' , 'page' , 'normal' ); | |
} | |
add_action( 'admin_menu' , 'doublee_remove_normal_excerpt' ); |
@doubleedesign small question what does the value 'temp' do in the following code snippet?
I don't remember for sure as this was written so long ago and I don't recall off the top of my head where I've used it to go and check, but judging from its usage in doublee_run_custom_excerpt_meta_box()
I think it was to make sure no other metaboxes are moved.
Adding this metabox to the "temp" group rather than the standard "normal", "side", or "advanced" means this code doesn't unintentionally move other metaboxes to under the title.
(Saying "advanced" metaboxes on line 18 would be an oversight, a throwback to some similar piece of code that it was initially copied from and then edited. I believe that should also say "temp".)
Looking at the docs, it says "Available contexts vary from screen to screen" and describes "normal", "side", or "advanced", but doesn't say that those are the only valid options. So given that and the above, I believe you can create your own contexts and that's what I did here.
Hope this helps! I haven't looked any deeper into it today than reviewing this gist and the docs, so if you do find differently feel free to correct me here if you have a moment - I always appreciate suggestions to improve my snippets :)
@doubleedesign small question what does the value 'temp' do in the following code snippet? I couldn't see this as a valid option in the WordPress documentation: https://developer.wordpress.org/reference/functions/add_meta_box/#parameters