How To Only Show Top-Level Pages When Choosing Parent Attribute

March 8th, 2013 - Posted by Steve Marks to PHP, Web Development.

Whilst recently working on a site built in WordPress I had a site structure that would never go more than two levels deep. As a result I wanted to make it impossible for a user to set a page three levels deep, and managed to do this by limiting the pages they could select as the ‘Parent’. By only showing the top level pages it not only gave me the result I wanted, but also made the list of parent pages smaller and more manageable.

The Solution

To accomplish the refinement of the ‘Parent’ dropdown options shown when editing the page attributes, I simply added the following code to my themes functions.php file.

// Only show parent pages when editing page
add_filter( 'page_attributes_dropdown_pages_args', 'admin_top_level_pages_only' );

// Also perform the same filter when doing a 'Quick Edit'
add_filter( 'quick_edit_dropdown_pages_args', 'admin_top_level_pages_only' );

function admin_top_level_pages_only( $args )
    $args['depth'] = '1';
    return $args;
Tags: ,
This entry was posted on Friday, March 8th, 2013 at 6:49 pm by +Steve Marks and is filed under PHP, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (0)

No comments have been left yet. Be the first