2

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.

Any ideas?

4

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
  • Thank you @s_ha_dum, I'll take a look at this and get back to you :-) May 24 '13 at 7:33
  • so this would work perfectly is I were using my own custom meta boxes, however I'm using Advanced Custom Fields, of which doesn't have an option to put the editor box elsewhere. I'm about to post my own answer to this question, your answer helped me get there :-) May 28 '13 at 12:57
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>

    <?
}
4
  • I would watch this carefully. There may be other consequences to removing editor support. I have never tried to remove it and then still use it in another box.
    – s_ha_dum
    May 28 '13 at 13:05
  • Yeah this was a concern I was trying to sidestep from the beginning, however it still appears to save and output the content... not sure what else it could cause problems with. May 28 '13 at 13:07
  • "...what else it could cause problems with..." -- I am not sure either, but it is possible that it could cause an issue somewhere. I'd have to really dig into the Core and see what that setting effects. Cautionary tale, that's all.
    – s_ha_dum
    May 28 '13 at 13:15
  • I'm might just do that... don't want this messing up. Many thanks, very helpful :-) May 28 '13 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.