WordPress Custom Page Templates Not Displaying In Dropdown

Last night while working on a WordPress theme I came across an odd bug with some custom page templates not showing up in the drop down menu when creating a new page. Sadly there wasn’t any information about it in the WordPress documentation or at the support forum. An hour or so of searching later and I did find a solution and thought I would post about what I found in case you or someone out there runs into a similar problem.

Custom Page Template Problem

You may be aware that WordPress allows you to create your own page templates.

The default Kubrik theme comes with two, the archives template and the links template, but you can create as many as you’d like.

These templates will be available to you in a drop down when create a new WordPress page or when editing an existing page as you can see in the dropdown to the left.

WordPress 2.7 seems to have an odd bug where some of your custom page templates won’t show up in the drop down and unfortunately my theme had been bitten by that bug.

While I was able to see some of the custom templates others were not visible at all in the template drop down and so were unavailable for use.

How To Get Your Custom Page Template To Show Up In The Drop Down

A little searching directed me to this post by Zach Graeve with a very simple solution. The trick Zach describes is to temporarily switch to another theme and then reactivate your theme. Doing that seems to reset the theme, kind of like rebooting your computer.

After a few more searches it seems as through the solution above works for most everyone. Alas, I’m not like most everyone and the solution didn’t work for me. Hopefully if you encounter this bug it works for you, since it’s about as easy as it gets to fix.

Back to searching which led me to another post on the missing dropdowns, by mkyong. The problem was the same and was occurring in version 2.5 of WordPress. The solution this time was going to the theme editor within the WordPress admin and select your page template to edit.

All custom page templates should start with the following code:

/*
Template Name: Custom Page Template Name
*/

which is a php comment that WordPress uses to identify page templates. In mkyong’s case and mine as well this bit of code was missing. What was particularly strange in my case was the code was in the file. That was the first thing I checked when I didn’t see the template listed in the drop down. Even stranger, I thought, was WordPress telling me I couldn’t save the file through the editor since the file didn’t have write permissions. Huh?

I checked permissions and indeed WordPress was right. How the permissions got that way is lost on me, but I set them back (755 for those of you who speak permissions) and I was able to add back in the php comment through the WordPress editor.

WordPress wouldn’t accept changes I made directly to the file in my usual code editor for whatever reason.

Once again all was right with the world or almost all right. WP still wouldn’t accept changes to the file through Coda, my editor of choice. When I opened things again tonight though, I seem to be able to make permanent changes in either editor and everything is indeed as it should be.

I realize most of you may never see this bug and perhaps stopped reading long ago, but this post is for the few of you who did encounter this problem and are having a hard time finding the solution. Hopefully you found this post and now know what to do.