Custom Page Templates Gone
after WordPress 3.4 Upgrade

wordpress-3-4

Update 6/27/2012:
This issue has been fixed in WordPress 3.4.1.

Question:

After upgrading my WordPress site to 3.4, the latest version, the custom page templates that came with my theme have disappeared!!!  Under Page Attributes –> Template in Edit Page I only get the “default template” for all my Pages, and it’s breaking my site!

Answer:

According to one of the WordPress developers, a little bug was introduced in 3.4 that is causing the custom page templates not getting parsed correctly.

Here’s a little background info:

When themes have custom page templates, each of these templates is actually a PHP file with the code that creates the page layout (See WordPress Codex for more info on custom page templates).  At the beginning of a page template PHP file, there is always a line of code that looks like this:

<?php /* Template Name:</span> Some Template Name Here */ ?>

Where:

  • <?php and ?> is standard PHP syntax, indicating the beginning and the end of a PHP code block.
  • /* Template Name: is what WordPress looks for and recognizes as the file as a custom page template file.  WordPress will then parse anything after the “:” and treats it as the template name.
  • Some Template Name Here is where you name your custom page template.  It can be anything you want.  In this example, we just use “Some Template Name Here” as a placeholder.
  • */ is the closing tag that lets WordPress knows that’s the end of the template name.

Right now in 3.4, when the PHP code is written all in one line, WordPress does not recognize the /* Template Name: … */ part of the code.

To get around the bug, simply put the /* Template Name: … */ part into its own line, like this:

<?php 
/* Template Name:</span> Some Template Name Here */
?>

This simple change will bring your custom page template back to the drop-down list.

And be sure you update ALL of your custom page template files that your theme has, in order to bring all of the templates back.

See Also:

WordPress bug report




  • Ryan

    Works perfect! 

  • Jane

    Thanks for the update! 🙂

  • Thanks for this. You just saved me a headache – and an afternoon.

    • You’re welcome! Glad it was helpful! 🙂

  • Did that. But now something else is wrong. What in the world is this?

    Parse error: syntax error, unexpected T_ENDWHILE in /home/(PATH OMITTED)/loop-page.php on line 38

    I didn’t even touch line 38. I never seen that woman in my life 😀

    • That means your server encountered an error while parsing (interpreting) the PHP code in loop-page.php, and it stopped at line 38.

      Unfortunately without seeing the code, it’s hard to tell what exactly caused the error, but it was likely caused a typo of some sort in the lines above (prior to line 38). Try going through that section of the code (lines 1-38) and make sure all the syntax is written correctly.

      If loop-page.php wasn’t the file you changed, then make sure whatever template files you just modified have the correct syntax.

      • update: Code seems to be fixed but now the page doesn’t carry over the entire layout. What can I do?

        http://merchantofnewyorkcity.com/new-page-template/

        • Looks like there’s some sort of coding mistake in your template php file. Although the syntax of your code seems to be correct (i.e. you didn’t get PHP errors from your server), the fact that I can see the code get_header(); ?> in the page means your code wasn’t written correctly. You might want to check the code that leads up to get_header(); and see if there’s anything missing, misspelled or written in the wrong order.

  • Sorry for the late reply. Your comment was thrown in the Spam pile by DISQUS and I just dug it out… 🙁

    It doesn’t mean the instructions are bad… It could be something very simple like a typo or missing character.