Move SEOPress Metabox under the ACF fields

SEOPress is a neat little plugin with a big impact. The most important META tags for SEO can be edited directly in the input mask for every page and every post – and a small preview shows how the page would be displayed in the search results.

However, the plugin has a habit of jumping the queue. At least if you use ACF fields, the SEOPress metabox may appear before the ACF fields. This can be a bit annoying. With a few lines of code, however, the SEOPress metabox can easily be moved to the bottom.

Move SEOPress under the ACF fields

/* move SEOPress meta box down */
add_action( 'add_meta_boxes', function() {
global $wp_meta_boxes;

$post_type = 'page';

// Get seopress meta boxes
$seopress_meta_box = $wp_meta_boxes[$post_type]['normal']['high']['seopress_cpt'];
$seopress_analysis_meta_box = $wp_meta_boxes[$post_type]['normal']['high']['seopress_content_analysis'];

unset( $wp_meta_boxes[$post_type]['normal']['high']['seopress_cpt'] );
unset( $wp_meta_boxes[$post_type]['normal']['high']['seopress_content_analysis'] );

// Move it to 'advanced' location with 'low' priority.
if ( empty( $wp_meta_boxes[$post_type]['advanced'] ) ) {
$wp_meta_boxes[$post_type]['advanced'] = [];
}
if ( empty( $wp_meta_boxes[$post_type]['advanced']['low'] ) ) {
$wp_meta_boxes[$post_type]['advanced']['low'] = [];
}
$wp_meta_boxes[$post_type]['advanced']['low']['seopress_cpt'] = $seopress_meta_box;
$wp_meta_boxes[$post_type]['advanced']['low']['seopress_content_analysis'] = $seopress_analysis_meta_box;

}, 99 );

If the SEOPress metabox is to be moved immediately for several content types (or custom post types CPT) below the ACF fields, the code only needs to be encapsulated in a corresponding foreach loop. The variable ‘post_type’ is replaced by the array ‘post_types’:

/* move SEOPress meta box down */
add_action( 'add_meta_boxes', function() {
global $wp_meta_boxes;

$post_types = array('post','page','custon_post_type');

foreach($post_types as $post_type) {

// Get seopress meta boxes
$seopress_meta_box = $wp_meta_boxes[$post_type]['normal']['high']['seopress_cpt'];
$seopress_analysis_meta_box = $wp_meta_boxes[$post_type]['normal']['high']['seopress_content_analysis'];

unset( $wp_meta_boxes[$post_type]['normal']['high']['seopress_cpt'] );
unset( $wp_meta_boxes[$post_type]['normal']['high']['seopress_content_analysis'] );

// Move it to 'advanced' location with 'low' priority.
if ( empty( $wp_meta_boxes[$post_type]['advanced'] ) ) {
$wp_meta_boxes[$post_type]['advanced'] = [];
}
if ( empty( $wp_meta_boxes[$post_type]['advanced']['low'] ) ) {
$wp_meta_boxes[$post_type]['advanced']['low'] = [];
}
$wp_meta_boxes[$post_type]['advanced']['low']['seopress_cpt'] = $seopress_meta_box;
$wp_meta_boxes[$post_type]['advanced']['low']['seopress_content_analysis'] = $seopress_analysis_meta_box;

}
}, 99 );

Based on “WordPress: Change meta box location”
https://deluxeblogtips.com/wordpress-change-meta-box-location/

See also “Moving meta boxes in admin”
https://wordpress.stackexchange.com/questions/166825/moving-meta-boxes-in-admin

Also here: “How to reorder meta box position?”
https://wordpress.stackexchange.com/questions/57897/how-to-reorder-meta-box-position