Add Post Template Section on Post Editor – WordPress | Without Plugins

Add post attribute to set or change something on post’s look using post template. You want to add post template section on custom theme. So use simple code on your WordPress’s Theme.

How to Do

  • Open functions.php file of active theme.
function add_custom_post_template($post_templates, $wp_theme, $post, $post_type) {
if ($post_type === 'post') {
$post_templates['page-template1.php'] = 'Post Template 1 Name';
$post_templates['page-template2.php'] = 'Post Template 2 Name';
}
return $post_templates;
}
add_filter('theme_post_templates', 'add_custom_post_template', 10, 4);
  • Now paste given code then SAVE.
Note
  • Make post template file and replace to green highlighted php file.
  • Rename blue green highlighted post template name.

Hope this code works on your custom theme. Have another type of help, So contact-us, Thank Your