Technology

Limit pages in WordPress’ Page Attributes “Parent” page

I am currently transferring the law dictionary portion of this website from the DokuWiki backend to integrating the entries therein as pages in this WordPress installation.

Each individual entry is a subpage of the page of the first letter of the entry, which is in turn a subpage of the page for the dictionary “frontpage” itself.

With 1,000+ entries to create as pages in this WordPress installation, the “Parent” attribute under Page Attributes quickly become unwieldy:

(I am using the Classic Editor.)

Looking through the Settings, there is nothing to change the level to just two (top page and first level subpage).

There is also no plugin to do the trick, and going through the hassle of creating a meta_box callback myself does not seem justified, especially that I have plans of automating the conversion of the pages themselves.

Looking through the documentation, the dropdown list is produced by the wp_dropdown_pages function which is defined in wp-includes/post-template.php.

We simply change the default to 2 instead of 0 (maximum):

function wp_dropdown_pages( $args = ” ) {
$defaults = array(
‘depth’ => 2,
‘child_of’ => 0,
‘selected’ => 0,
‘echo’ => 1,
‘name’ => ‘page_id’,
‘id’ => ”,
‘class’ => ”,
‘show_option_none’ => ”,
‘show_option_no_change’ => ”,
‘option_none_value’ => ”,
‘value_field’ => ‘ID’,
);

Thus, we get this:

More manageable now.

I know, this is quick and dirty and would be overwritten when I update my installation. But it works.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.