Why Are Page Templates Not Working?!

Written by:
Posted in: ,
Published: January 5, 2018

WordPress 4.9.2 has a bug!

Or, what some my say, not intuitive behavior. 

When adding page templates to a WordPress theme during development, those templates may not show up in the dropdown menu on the edit screen. This is because the list of those files is now cached, and the cache is refreshed every hour. Or, in WordPress development speak, the list of files is added to a transient. This happens in /wp-includes/class-wp-theme.php on line 991, currently.

Here is the bug report: https://core.trac.wordpress.org/ticket/42573

From the discussion, it seems this issue will be fixed with the next release, sometime at the end of January, 2018. It sounds like they’ll either remove the caching of these files, or disable it if WP_DEBUG is set to true.

The work around is to increment the theme version number. This changes to transient key.

 

If this does not solve your problem try these:

Make sure you have specified a template name.

    /**
    * Template Name: Front Page
    */

Make sure your template name is different than any other template.

    
   /**
    * Template Name: Different Name
    */

Do not use ‘page-‘ as a prefix.

WordPress will interpret that as a template for a specific page slug, not as a global template for use on any page.

Put them in a folder called ‘page-templates’

While this is not required, WordPress recognizes this folder name. Therefore, it’s a good idea to store your global page templates to help keep them organized. Otherwise, they should be in the top level theme directory. If you’re using a child theme, they should in the the top level child theme directory (or in a folder called ‘page-templates.’.

Read more here: https://developer.wordpress.org/themes/template-files-section/page-template-files/