Creating a Custom Template for a Specific Post

Developing for WordPress in Exeter and Plymouth

Quick and Dirty WordPress Development Tip #1

There’s a lot of info out there about custom post types in WordPress. For example, there’s an excellent article here. But what if you only want to tweak the appearance or functionality of a single post? It seems a bit excessive to make a whole new custom post type for a one-off situation.

Enter WordPress’s super-cool file-naming system to the rescue!

Working on a child theme, as you absolutely should be, just create a file with the following format: single-post-{post-title}.php. For example, your file might be named single-post-spain.php. Then you can copy the contents of your parent theme’s single.php file, and make any changes you want. When the post with the named title is displayed, WordPress will automatically use the correct file.

This is similar to the method for displaying custom post types using single-{post-type}.php, but saves you having to make a new post type.

I hope this was helpful. Look out for future quick and dirty WordPress Development tips.