How to disable Page Attributes dropdown in wp-admin

As discussed at WordPress admin screen very slow / timing out when editing or adding a new page/custom post

I am having a similar issue on a WP site containing 7,784 pages. Edit screens are slow loading due to the rendering of all 7k pages in the source code for the Page Attributes dropdown menu. Besides editing core, there must be a better way to deal with this. Seems like a flaw to render all pages on the edit screen.

Read More

Feedback from others with high volume/traffic WP sites much appreciated!

Related posts

5 comments

  1. Removing support for page attributes will prevent that box from appearing…

    function remove_page_attribute_support() {
        remove_post_type_support('page','page-attributes');
    }
    add_action( 'init', 'remove_page_attribute_support' );
    

    … but I don’t know if you need attributes support or not. If you don’t that is the fix.

    If you do, you will need to remove the box as per @KrzysiekDrozdz’s answer, but to be able to use those attributes you will have to rebuild that box, the original is here, in such a way that it works for you.

  2. Just use remove_meta_box function:

    if (is_admin()) :
    function my_remove_meta_boxes() {
        remove_meta_box('pageparentdiv', 'page', 'side');
    }
    add_action( 'admin_menu', 'my_remove_meta_boxes' );
    endif;
    

    If you need to set hierarchy of these pages (set post_parent for pages), you can still do it. Just add your custom meta box, and place there a select box with list of pages.

    You have to be sure, that your query (to select these pages) is more efficient thatn original though. You can list pages without hierarchy and select only title and page_id (original query will retrieve all page data from DB, and it can be a lot of data, if there are many pages), or something like that.

  3. Another option is to filter the dropdown arguments before a call is made to wp_dropdown_pages. This function has a hook, but it happens after the query was made.

    There are two places where it can be filtered: in Quick Edit mode and the Page meta box. But none is available for Options Reading or Theme Customizer.

    enter image description here

    The following are the default arguments and an example of filter to restrict pages by author (depth, child_of and exlcude seems good candidates too).

    /*
    $defaults = array(
        'depth' => 0, 
        'show_date' => '',
        'date_format' => get_option('date_format'),
        'child_of' => 0, 
        'exclude' => '',
        'title_li' => __('Pages'), 
        'echo' => 1,
        'authors' => '', 
        'sort_column' => 'menu_order, post_title',
        'link_before' => '', 
        'link_after' => '', 
        'walker' => '',
    );
    */
    
    add_filter( 'quick_edit_dropdown_pages_args', 'limit_parents_wpse_106164' );
    add_filter( 'page_attributes_dropdown_pages_args', 'limit_parents_wpse_106164' );
    
    function limit_parents_wpse_106164( $args )
    {
        $args['authors'] = 'author_name';
        return $args;
    }
    
  4. You can easily disable page attribute dropdown using below code.

    add_action( 'admin_init', 'tryvary_remove_feature_meta_box' );
    function tryvary_remove_feature_meta_box() {
        remove_post_type_support( 'page', 'page-attributes' );
    }
    

    Just try to remove page attribute feature using admin_init hook. If it’s doesn’t work for you then try below code.

    add_action( 'admin_head', 'misha_remove_meta_box', 1 );
    function misha_remove_meta_box(){
        remove_meta_box( 'pageparentdiv', 'page', 'side' );
    }
    

    Try to remove meta box code using admin_head hook.

    You will get more information about remove meta box and feature from this article.

  5. I finally found a solution. Not the best one, but it’s working.
    remove_meta_box and similar functions only works after the meta_box is added. Otherwise there is nothing to remove. So unfortunally that didn’t work out for me.
    What was really working is a simple # to comment a line out of meta-boxes.php

    if ( post_type_supports( $post_type, 'page-attributes' ) || count( get_page_templates( $post ) ) > 0 ) {
        #add_meta_box( 'pageparentdiv', $post_type_object->labels->attributes, 'page_attributes_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
    }
    

    So you prevent the meta-box of getting loaded with all includes and thats it. Pages loading fast now. =)

Comments are closed.