share

Select Custom WordPress Post Type Template

April 22, 2018 | Dev / Code, Wordpress

add custom post type to WordPRess

So you’re building a custom WordPress theme and you’re just about finished.

You have our HTML templates created but you want to convert them into WordPress.

You have different page styles and designs, so you’ll need custom page templates for all of the different page layouts.

An easy solution for this is to simply create the page templates in PHP and either write in the content and images in HTML.

But, let’s say you want to be able to edit the content or images from within the WordPress dashboard using their editor or, likely a common case for most WordPress developers: your client wants to be able to edit the page’s content.

Now, the chances of them having experience with editing HTML or using an FTP client are probably pretty slim.

To create an editable page template, your workflow might look a little something like this:

  1. Create a PHP page template in your theme
  2. Add the Advanced Custom Fields plugin and create your fields
  3. Create the page in WordPress
  4. Select the page template you want to use when editing that page
custom wordpress page template selector

When it comes to adding templates to pages, the process is pretty straightforward.

But adding the same functionality to WordPress Posts seems to be a common question asked in the development community.

One of the greatest things about using WordPress is the ever-growing community willing to help one another.

It seems like there is a plugin for every issue or need developers may have.

Plugins for selecting custom post templates in WordPress

  1. WP Custom Post Template
  2. Custom Post Template By Templatic
  3. Custom Post Type Page Template

While plugins can solve issues you may not be able to solve on your own (and potentially save you a shitload of time), sometimes we want to do stuff on our own.

There is also a handful of other reasons why you want to avoid using a WordPress plugins like security, pagespeed, etc.

When I first started learning WordPress development, I took to Google to find out how to create custom post templates, but finding an answer was a little more difficult than I expected.

Luckily, the solution is actually very simple.

How to add a custom template selector to a WordPress Post

  1. Access your website via FTP
  2. Create a page template (let’s say full-width-post.php)
  3. Open the file and add the content below

 


<textarea readonly="readonly" style="color: #03fc96; height: 350px; background: transparent;">/*
Template Name: Full-Width Template
Template Post Type: post, page, product
*/
get_header();
?&gt;

/*---Add your content here---*/

&lt;!--?php get_footer(); ?--&gt;
</textarea>

And that’s it!

Now you can create a new post and on then you’ll see the “Post Attributes” box with a dropdown arrow to select your custom post template.

You shouldn’t have to add anything to your functions.php file.

Simply having a php file with “Template Name: Full-Width Template Template Post Type: post, page, product” in the meta info will do the trick.

Check out more of our WordPress tips, tutorials, and resources.

Share This Article

related articles

some sponsors

Haven’t signed up for our newsletter?

Be a lot cooler if ya did


We send nothing but the good shit. Once a week. That’s it.

Be a lot cooler if ya did

UX and Web Design blog articles
Web Development & Coding blog articles
Lifestyle blog articles
Branding blog articles
Graphic design blog articles
Software reviews blog articles

Time's up, let's do this

Stay up-to-date with all of the design and creative news, resources, and inspiration by signing up for the CreativesFeed newsletter!