Template Page Attributes for Custom Post Type [WP Support] « RainaStudio

Template Page Attributes for Custom Post Type [WP Support]

Hey there, I am here for today for a quick tutorial. Recently, we have switched the Genesis Framework to the Focusblog theme by Thrivetheme. That’s why we had to update many designs and functions. Template page attributes for custom post type is one of them.

We have two custom post types registered, “Code Snippet” and “Case Studies.” I wanted to use the existing theme template for these post types. But, Template from Page Attributes available for only ‘page’ post type.

So, here are what we did to achieve that.

Enable TEMPLATE Page Attributes for CPT on WordPress

To do this, you’ll need to open the code you wrote to register custom post type(CPT). In my case, the following is the example code I added.

If you look at the code, you’ll notice “‘hierarchical’ => true,“. It is one of the arguments which is false by default. We need it to make true when we added “‘page-attributes’” to supports parameter.

Add “‘hierarchical’ => true,” or edit if “‘hierarchical’ => false,” to “‘hierarchical’ => true,“. Add “‘page-attributes’” to the supports parameter. As sooner as you save the file after adding this, you’ll see Page Attributes in the sidebar, like the screenshot below.

Page Attributes for CPT

Add Template Post Type to Existing Templates

Alright, now we are in the next/final part of the job. One of the fantastic enhancements was delivered in WordPress 4.7 for the template system. Using that enhancement, we can handle any template for any custom post type(CPT).

So, here is the part we are going to play around. The theme which we are using for RainaStudio has BLANK, FULL-WIDTH, LANDING, & NARROW page template. So, I open all templates one by one and add “Template Post Type: post, page, projects, code” after “Template Name.”

Here is the original code snippet, before adding template post type.

And the snippet after adding template post type.

As sooner as I saved the file, code had taken into action. And the image below of Template selection.

Template Page Attributes


Being a thinker without box, I am not good at writing a conclusion. So far, if the tutorial works for you, share it with your friends and WordPress community. And your comment always much appreciated.

Anwer Ashif

I like to quote code snippet, fix things like error 503 service unavailable. Cycling, traveling and plantation are my hobbies.