Categorizing Page Templates

Great question. As far as I can tell there isn’t a way to filter this list (there’s a long trac ticket about a proposal to, if you’re interested, and also related (but different) questions on this site here and here).

Because there’s no filter, you may have to resort to doing it with jQuery.

We can add our own scripts to the admin footer using the admin_print_footer_scripts action:

add_action("admin_print_footer_scripts", "wpse_227485_categorise_page_templates");

function wpse_227486_categorise_page_templates(){
  ?>
  <script>
    // run scripts here
  </script>
  <?php
}

What we then need to figure out is how to access and categorise the templates.

Looking at the source for the post editor page, the templates are inside the #pageparentdiv in a select element called #page_template. So we can access its options like so:

jQuery("#pageparentdiv #page_template option")

Using this, you can effectively ‘categorise’ the templates in a custom way by adding additional blank, disabled options above the item you know you wish to categorise it at, for example:

jQuery("#pageparentdiv #page_template option[value="my-template.php"]")
  .before("<option disabled='disabled'>My Template Heading</option>");

Putting the above block of code in place of the section marked // run scripts here in the first block above will add ‘My Template Heading’ as an unselectable option above wherever the template ‘my-template.php’ is in the list.

Of course, add as many of these wherever you need them 🙂

It’s important to note this isn’t going to be dynamic in any way – but that could be coded in depending on exactly what you wanted. There’s no built-in way in WordPress to have templates defined as being for parent pages/child pages etc., but if you needed this to be dynamic you could theoretically approach that in different ways such as adding a custom variable to the top of the template files and then reading them before generating this script.