Skip to content

Dynamic Template Parts

When building dynamic templates, you can select a template type; one option is Part. In this article, we’ll explain the purpose of dynamic template parts and walk you through how to create and use them.

What are Template Parts?

A template part is a reusable template that can be displayed anywhere on your site using either a standalone shortcode or the Template Part element.

For example, if your site has multiple post types, each with its own single dynamic template, and you want to include the same advertisement across all of them, a template part is the perfect solution. You can create a template part for the advertisement and insert it into each single template. This allows you to manage the advertisement content from one central location.

Template parts are not limited to use within dynamic templates. They also work well with Custom Actions, making it easy to insert extra content in specific theme locations. Additionally, they can be used to override default theme elements, such as replacing the page header title with a dynamic template.

Creating a Template Part

First go to Theme Panel > Dynamic Templates and create a new template.

Now you can add whatever you want to your template then select your Template Type from the site: be sure to select the Part type.

Using Your Template Part

There are 2 ways to use your template part; a shortcode or the Template Part element.

Using the Template Part Element: To insert your template using a page builder like WPBakery or Elementor, simply add the Template Part element and select your desired template. Below is a screenshot showing how this looks in WPBakery.

Using the Shortcode: If you are displaying a template part outside of a page builder, such as in a custom snippet or in the Custom Actions Panel then you will want to use the wpex_template shortcode. You can easily locate your template part shortcode by sorting your admin templates like such:

Custom Actions Panel Notice: If you’re adding your template part to the Custom Actions panel, it’s a good idea to wrap it in a <div> with the container class. This ensures that your template aligns properly with the rest of your site’s layout. For example:

<div class="container">[wpex_template id="1"]</div>
Back To Top