Skip to main content
2 of 2
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/

What you need to do is compare the values of the meta field _wp_page_template, which contains the page template selected for a single page with the available page templates.

For this you need to construct an array of used templates, because you want the templates used by all the pages, similar as shown here:

Use array_unique to get unique values.

Then you need to get the available page templates, as shown here:

Last but not least, you can use array_diff to compare the arrays of used and available templates, which subsequently gives you the unused templates.

Nicolai Grossherr
  • 18.9k
  • 8
  • 64
  • 109