Creating a custom single post template in WordPress allows you to apply unique layouts or designs to specific blog posts. This is great for special content like case studies or feature stories. Follow these steps to create and apply a custom single post template within your WordPress theme.
Access Your Theme’s Files
To start, access your theme files. It’s best to create a child theme to ensure your customizations aren’t overwritten with updates.
- Create a child theme if you haven’t already.
- Go to Appearance > Theme Editor or use FTP to access your theme files.
Create a New Template File
- In your child theme folder, create a new file named single-custom.php.
- At the top of the new file, add this PHP code:
- Save single-custom.php in your theme or child theme directory.
Add Basic Template Structure
- Open single.php in your theme and copy its contents.
- Paste the code into single-custom.php and save it. This provides your custom template with the header, footer, and layout of your main single post template.
Customize the Template Layout
Make edits to the layout and structure in single-custom.php:
- Move the Title: To place the title below the featured image, find and move this line:
- Add Custom Fields: If you use custom fields, display them by adding code like this where you want them to appear:
- Customize the CSS Classes: Add unique CSS classes for styling, for example:
Add CSS Styling
Open your theme’s style.css file (or the child theme’s style.css file) to add custom styling for this post layout. For example:
This will give your custom posts a different background color and larger title font.
Apply the Template to a Post
- Go to Posts in the WordPress dashboard.
- Edit an existing post or create a new one.
- In the Post Settings sidebar, find the Template option.
- Select Custom Single Post from the dropdown and save or publish the post.
Your custom template will now apply to this post, using the unique layout and styling you created.