Fixing an old, broken WordPress page


I got quite a rude shock recently to discover the archive page wasn't working! if you've been using WordPress for a long time and suddenly a custom page of yours is rendering blank, maybe this might come in handy.

Explanation sounds like an expired "planation"

When I first started using WordPress in 2005 I created a custom page template for the archive page, because I didn't like the way WordPress didn't (and still doesn't!) have a basic index feature.

The problem is, you can't call the WordPress API within a regular post or page because WordPress (for good reason) sanitises any code. The workaround is to create a custom page template in your theme that displays what you want, then selecting it from the "template" drop down box for the page you want to change in the WP admin interface.

For example, I had nicearchive.php in my theme folder which called the code to render the list of posts. It was called Nice Archive List, and I had it selected as a template for my Archive page which was otherwise blank.

I remember doing this for my archive page five years ago, but I'd noticed starting around WordPress 2.x that the template drop down menu didn't reference anything for the archive page. I didn't really care, because it still worked. Somehow!

Smite and solution to being smite-ed

Maybe it was the latest WordPress update that did it, but suddenly the archive page stopped working and instead rendered a blank, generic page. Obviously the voodoo association between page and the custom page template file was finally severed.

Going into the custom template file for that page I noticed it didn't have any template header code at all.

<?php /*
Template Name: Nice Archive List
*/ ?>

After adding this to the page template file, I was able to go to the archive page in the WP admin screen and choose the template from the template drop down box. Now the page renders properly again.

This raises several questions! First, how did the template work before without those necessary lines? Did older versions of WordPress handle page templates differently? Did the animators of K-On expect otaku to obsess over Mugi's eyebrows to the extent they did, or did it catch them off guard? If so, they're smart for using it as a plot device later XD. I haven't got around to reading the manga.Mi

Author bio and support


Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person. Hi!

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite bespoke cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.