Custom template for posts

In the active WordPress theme folder (desired, child-theme), you can create a file – for example, template-without-sidebar.php, in which will pass the code:

<?php
/*
* Template Name: Post without sidebar
* Template Post Type: post
*/

We will see, when creating a new article, that in the side part of the editing panel, the Post Attributes section will appear where, as on the pages, we can choose one of the particular templates, created later.

Compared to single-{post_type}.php files, which apply to all posts of that type, with templates declared as above you can configure templates that apply only to a limited number of articles, but can also be used for several types of items.

Source: Post Type Templates in 4.7

Author: Ovidiu.S

I am quite passionate about this professional area as if I know something - no matter how little - I want to share it with others.

Leave a Reply