Customize-Templates-For-Specific-Posts-Without-Plugin-In-WordPress-

Add Custom Template For Specific PostIn WordPress

Table of Contents

To add a custom template for a specific post in WordPress: 1. Insert provided code into functions.php 2. Duplicate single.php in theme folder 3. Rename duplicate as single-{Post ID}.php 4. Find Post ID in edit page URL This method allows unique layouts for individual posts without affecting others.

Original Post

〈Add Custom Template For Specific PostIn WordPress〉


There are two things you need to do. First, copy and paste the code in your function.php file. Second, find the single.php in your theme folder. This file is the template of posts. Duplicate it, and rename as single-{Post ID}.php.

add_filter( 'single_template',  'check_post_custom_template');
 function check_post_custom_template($template){
     global $post;
     $custom_template = locate_template( "single-{$post->ID}.php" );
     if ( ! empty( $custom_template ) ) {
         $template = $custom_template;
     }
     return $template;
 }

And how to get your Post ID? You can enter the post edit page, then get it in the link. For example, the edit page link of the post is below, and “post = 123456” is your post ID.

https://aronhack.com/wp-admin/post.php?post=123456&action=edit

Related Posts

The Complete WordPress Customization Tutorial – Just Copy And Paste And Work

🚀 Unlock Ads-Free Experience At $5/year

✓ 14 days free trial ✓ Cancel anytime

3 thoughts on “Add Custom Template For Specific PostIn WordPress”

Leave a Comment

Your email address will not be published. Required fields are marked *