Modifying the main editor priority

I want the main WordPress post editor to appear below some of my meta boxes (generated by Advanced Custom Fields).

I know there are the add_meta_box() and remove_meta_box() functions, however it’d be really awesome if I could just modify the editor meta box priority without having to remove and add it again.

Read More

Any ideas?

Related posts

2 comments

  1. The editor is hard-coded into the form. It isn’t inserted by add_meta_box.

    There is a hook called edit_form_after_title which you should be able to use though.

    Proof of concept:

    // use the action to create a place for your meta box
    function add_before_editor($post) {
      global $post;
      do_meta_boxes('post', 'pre_editor', $post);
    }
    add_action('edit_form_after_title','add_before_editor');
    
    // add a box the location just created
    function test_box() {
        add_meta_box(
            'generic_box', // id, used as the html id att
            __( 'Generic Title' ), // meta box title
            'generic_cb', // callback function, spits out the content
            'post', // post type or page. This adds to posts only
            'pre_editor', // context, where on the screen
            'low' // priority, where should this go in the context
        );
    }
    function generic_cb($post) {
      var_dump($post);
      echo 'generic content';
    }
    add_action( 'add_meta_boxes', 'test_box' );
    
  2. To answer my own question, I’ll first explain why @s_ha_dum’s answer doesn’t work for me.

    I’m using Advanced Custom Fields to add the extra meta boxes, the ones I need to appear above the WordPress editor.

    @s_ha_dum pointed out that the WordPress editor is hardcoded within the template, but I noticed it can be disabled by removing support for the editor. With this in mind I’ve disabled support for the editor, then added the code for the editor in a new meta box.

    Et voila:

    add_action('init', function () {
        remove_post_type_support('post', 'editor');
    });
    
    add_action('add_meta_boxes', function () {
    
        $screens = array('post');
    
        foreach ($screens as $screen) {
    
            add_meta_box(
                'moved_editor',
                'Moved Editor',
                'moved_editor_custom_box',
                $screen
            );
    
        }
    
    });
    
    function moved_editor_custom_box( $post ) {
    
        // Use nonce for verification
        wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );
    
        ?>
    
            <style>
    
                #moved_editor {
                    border: none;
                }
    
                #moved_editor h3 {
                    display: none;
                }
    
                #moved_editor .inside {
                    padding: 0;
                }
    
            </style>
    
            <div id="postdivrich" class="postarea">
    
                <?php wp_editor($post->post_content, 'content', array('dfw' => true, 'tabfocus_elements' => 'sample-permalink,post-preview', 'editor_height' => 360) ); ?>
    
                <table id="post-status-info" cellspacing="0">
    
                    <tbody>
    
                        <tr>
    
                            <td id="wp-word-count"><?php printf( __( 'Word count: %s' ), '<span class="word-count">0</span>' ); ?></td>
                            <td class="autosave-info">
    
                                <span class="autosave-message">&nbsp;</span>
    
                                    <?php if ( 'auto-draft' != $post->post_status ) : ?>
    
                                        <span id="last-edit">'
    
                                            <?php if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) : ?>
    
                                                <?php
    
                                                    $last_user = get_userdata($last_id); 
                                                    printf(__('Last edited by %1$s on %2$s at %3$s'), esc_html( $last_user->display_name ), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));
    
                                                ?>
    
                                            <?php else : ?>
    
                                                <?php printf(__('Last edited on %1$s at %2$s'), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified)); ?>
    
                                            <?php endif; ?>
    
                                        </span>
    
                                    <?php endif; ?>
    
                                </td>
    
                            </tr>
    
                    </tbody>
    
                </table>
    
            </div>
    
        <?
    }
    

Comments are closed.