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

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.