15

What's the best way to completely customize the Edit Post admin screen for a specific custom post type?

I have customized it to an extent already on creation of the custom post type - adding additional fields etc, but I want to remove many of the elements such like permalinks, preview post, disable quick editing etc

16

Some of these questions are answered here: Set Default Admin Screen options & Metabox Order

To remove the permalink metabox:

function my_remove_meta_boxes() {
    remove_meta_box('slugdiv', 'my-post-type', 'core');
}
add_action( 'admin_menu', 'my_remove_meta_boxes' );

additionaly, you will have to hide #edit-slug-box with css or javascript. see: Loading External Scripts in Admin but ONLY for a Specific Post Type?

To disable quick edit:

function my_remove_actions( $actions, $post ) {
    if( $post->post_type == 'my-post-type' ) {
        unset( $actions['inline hide-if-no-js'] );
    }
    return $actions;
}
add_filter( 'post_row_actions', 'my_remove_actions', 10, 2 );

To change the preview link, you could use the filter 'preview_post_link', but it works only when the post has not yet been published. So, the solution would be to remove the submit meta box and add your own modified one:

function my_replace_submit_meta_box() {
    remove_meta_box('submitdiv', 'my-post-type', 'core');
    add_meta_box('submitdiv', __('Publish'), 'custom_post_submit_meta_box', 'my-post-type', 'side', 'core');
}
add_action( 'admin_menu', 'my_replace_submit_meta_box' );

function custom_post_submit_meta_box() { // a modified version of post_submit_meta_box() (wp-admin/includes/meta-boxes.php, line 12)
    ...
}
  • Thanks so much. Been searching for the answer to this for ages! Also, is there a way to change where the Preview button in the Publish box links to? I'd like it to link to mysite.com/video?id='id of post' or open up a lightbox with a video player – fxfuture Sep 28 '10 at 5:07
  • Hi again - actually I can't get either of those bits of code you supplied to work. The permalink metabox just disables saving changes to the permalink rather than hiding it, and I can't disable the Quick Edit link at all. Any ideas? – fxfuture Sep 28 '10 at 6:40
  • I edited my answer. I just tested the quick edit code ad it works. You are talking about the quick edit link below the post name on: wp-admin/edit.php?post_type=sis_course, right? – sorich87 Sep 28 '10 at 7:07
  • Great, I'll have a look at the additional info you posted. I was able to hide the quick edit by changing 'hierarchical' => false in my custom post type. Doesn't seem to make a difference as I'm using the Post Types Order plugin to order it anyway. Thanks! – fxfuture Sep 28 '10 at 7:35
  • Replacing the submit meta box worked perfectly! It actually had to include $post between the brackets in your function - i.e. custom_post_submit_meta_box($post). So that's all three sorted :) There's quite a bit more customizing I want to do to both the list posts and edit post screen - do you know of a reference guide that details how to remove/replace all the different elements? – fxfuture Sep 29 '10 at 0:21

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.