How to Create Template Parts and Block Templates for Your Theme: A Complete Guide 11 minutes read Dec 24, 2025 8 Likes How Template Parts and Block Templates Power Modern WordPress ThemesThe block editor has moved WordPress into a new era where themes are no longer just PHP templates; they’re collections of block-based layouts that give developers more control and users more flexibility. Template parts and block templates play a massive role in this evolution, helping you structure your theme intelligently while keeping everything future-proof and incredibly customizable. Whether you’re building a classic theme, a hybrid theme, or a full block theme, understanding how to create and customize template parts and block templates is essential. This guide breaks the topic down into simple, actionable steps so you can confidently build modern WordPress themes that work seamlessly with Gutenberg. What Are Template Parts? Template parts are reusable sections of a theme, such as the Header, Footer, Sidebar, or any repetitive layout element. In block themes, they’re built using blocks and stored as HTML files instead of PHP. This makes editing them easier for both developers and end users. Why Use Template Parts? They keep your theme modular They let users customize sections without editing code They improve consistency across the site They integrate tightly with the Site Editor They reduce repetitive structure in templates Common template part examples include: header.html footer.html sidebar.html Custom template parts like hero.html, newsletter.html, etc. What Are Block Templates? Block templates define the structure of an entire page or post type using blocks. A template may include: Header block Content area Query loop Sidebar block Footer block CTA section Custom template parts You can create block templates for: Pages Posts Custom post types Archives 404 pages Search results WooCommerce templates Block templates live in your theme’s /templates directory and are written using block markup in .html files. Folder Structure for Templates and Template Parts To build block templates and template parts, ensure your theme follows this structure: your-theme/ ├─ templates/ │ ├─ index.html │ ├─ single.html │ ├─ archive.html │ └─ page.html ├─ parts/ │ ├─ header.html │ ├─ footer.html │ └─ sidebar.html └─ theme.json If your theme does not have these folders, you can create them manually. How to Create Template Parts Creating template parts is simple once you understand the block markup approach that Gutenberg uses. Create Your Template Part FileInside your theme, navigate to: /parts/ Create a file such as: header.html Add Block Markup Inside the FileBlock themes use HTML files that contain block comment markup, like this: This file now becomes a template part that can be reused anywhere in your theme. Register Template Parts via theme.jsonTo enhance flexibility, register template parts using the templateParts section: Include Template Parts Inside TemplatesIn your template, such as index.html: That’s it—your template parts are now dynamic and editable. How to Create Block Templates for Your Theme Block templates define the structure of entire pages. They replace legacy PHP templates. Create a Template File inside /templates/Example: single.html Add Your Page Layout Using BlocksSample block template for single posts: This defines the entire layout of your single post template. Create a Custom Template for Pages or CPTsIf you have a custom post type like portfolio, create: templates/single-portfolio.html Then add layout: WordPress automatically assigns the template to your custom post type. Using theme.json to Control Template Behavior The theme.json file is the heart of block theme configuration. It controls: Layout Colors Typography Spacing Borders Template parts Custom templates Register Block Templates via theme.json : You can tell WordPress about your templates like this: Now this template shows up in the Page Template dropdown.Build flexible WordPress themes with block templatesContact UsThe Way ForwardCreating template parts and block templates is a core skill in modern WordPress development. These tools let you build smart, flexible, modular themes where every section is reusable and customizable. By using block markup instead of PHP, you give users more creative freedom while keeping development clean and scalable. Template parts help you structure the repeatable sections of your theme, while block templates define the layout of entire pages, including custom post types, archives, and landing pages. Combined with the power of theme.json, you can style, register, and manage these templates effortlessly. Mastering template parts and block templates isn’t just about staying updated; it’s about building themes that are future-ready, user-friendly, and optimized for the new block-based era of WordPress.You may also like this: Understanding WP Cron: How It Works & How to Replace It With Real Cron JobsFree Consultation Name*Email*Phone Number*Description* wordpress website developerwordpress web design companyenterprise wordpress development agencywp theme developmentMaulik MakwanaDec 24 2025Maulik Makwana is a Team Lead with more than 10 years of experience in web development and technical leadership. He specializes in WordPress, Core PHP, custom plugin and theme development, WooCommerce, Elementor customization, JavaScript, jQuery, HTML5, CSS3, REST APIs, and website speed optimization. With a strong technical foundation and a results-driven mindset, he consistently delivers robust, scalable, and high-performance web solutions. He effectively manages development workflows, mentors team members, and ensures high standards of code quality, performance optimization, and timely project delivery aligned with business objectives.You may also like Using AI to Optimize WordPress Website Performance Read More Feb 11 2026 How AI Improves SEO for WordPress Websites Read More Feb 04 2026 How Agencies Use AI to Manage Multiple WooCommerce Sites Read More Jan 29 2026 Top AI Website Builders vs WordPress: Which Is Better? Read More Jan 29 2026 Automating WordPress Workflows with AI and Cron Jobs Read More Jan 29 2026 AI-Powered Dynamic Content on WordPress: Beyond Static Pages Read More Jan 26 2026