Lifetime updates on every purchase Support replies within 24 hours Secure checkout via Gumroad 8,500+ sales since 2016

Template parts

Updated 4 min read 1 view

Template Parts let you design the header, footer and other site-wide blocks in Elementor, then choose where each one appears with rules such as “Entire Website”, “All Posts” or “Only the Contact page”.

Needs: Elementor and Advanced Custom Fields Pro. The rule fields use ACF repeaters, which are part of ACF Pro.

Template types

TypeValueShown
HeaderheaderWhere its display rules match
FooterfooterWhere its display rules match
Above Footerabove_footerWhere its display rules match, typically a call-to-action above the footer
404 Page404On 404 pages. No rules needed.
SubmenusubmenuWherever the theme or a shortcode places it, for example inside a mega menu
CustomcustomWherever the theme or a shortcode places it

Creating a template part

  1. In the admin, open your theme’s menu and choose Template Parts. You can also use + New → Template Part in the admin bar.
  2. Click Add New and enter a title.
  3. Under Template Settings, choose a Template Type.
  4. For headers, footers and above-footer blocks, add Display Rules and, if needed, Exclude Rules.
  5. Optionally add a Note. It appears only in the admin list.
  6. Publish, then click Edit with Elementor to design the template.

The editor opens on a blank Elementor Canvas page. Template parts can’t be viewed on the front end by visitors; anyone who can’t edit posts is redirected to the home page.

Display and exclude rules

Each rule is one location. A template appears if any display rule matches and no exclude rule matches. A template with no display rules does not appear anywhere.

GroupRuleMatches
BasicEntire WebsiteEvery page
All SingularsEvery single post, page or custom post
All ArchivesEvery archive page
Special Pages404 PageThe 404 page
Search PageSearch results
Blog / Posts PageThe posts page
Front PageThe front page
Date ArchiveDate archives
Author ArchiveAuthor archives
WooCommerce Shop PageThe shop page
Post TypesAll PostsSingle items of that post type
All Posts ArchiveThat post type’s archive
All Categories ArchiveArchives of that taxonomy
Specific TargetSpecific PagesChosen posts, pages or terms

The Post Types group lists every public post type and taxonomy on your site.

When several templates match

If more than one published template of the same type matches a page, the one with the most specific rule wins:

PriorityRule
100Specific Pages
50Any Special Pages rule
40Taxonomy archive
30Post type archive
20All items of a post type
10All Singulars, All Archives
1Entire Website

For example, with a site-wide header set to Entire Website and a second header set to Specific Pages → Contact, the Contact page uses the second header and every other page uses the first.

A template’s priority is the highest priority among its display rules.

Shortcode

Every template part has a shortcode, shown in the Shortcode box on the edit screen and in the admin list. Click it to copy.

[vlt_template_part id="123"]

The shortcode renders any template part type, ignoring display rules. Use it for Submenu and Custom templates, or to place a block inside other content.

Output:

<div class="vlt-tp-template" data-template-id="123">…</div>

Rendering in a theme

The plugin doesn’t change your theme’s header.php or footer.php. The theme asks for the matching template through a filter and decides what to do when nothing matches:

// header.php
$header = apply_filters( 'vlt_toolkit_tp_header', '' );

if ( $header ) {
	echo $header; // phpcs:ignore WordPress.Security.EscapeOutput
} else {
	get_template_part( 'template-parts/header/default' );
}
FilterReturns
vlt_toolkit_tp_headerMatching header
vlt_toolkit_tp_footerMatching footer
vlt_toolkit_tp_above_footerMatching above-footer block
vlt_toolkit_tp_404404 template

Each returns an empty string when no template matches. Otherwise it returns the Elementor content wrapped like this, with the template’s CSS already enqueued:

<div class="vlt-tp vlt-tp--header" data-template-id="123">…</div>

Listing templates

To fill a theme option or a select control with template parts of one type:

$submenus = vlt_toolkit_populate_template_by_type( 'submenu' );
// [ 123 => 'Services mega menu', 456 => 'Shop mega menu' ]

$all = vlt_toolkit_populate_template_by_type(); // every type

Technical details

Post typevlt_tp
Capability needed to create, edit or deletemanage_options
ACF field groupgroup_vlt_tp_settings
Meta fieldstemplate_type, display_rules, exclude_rules, note

The admin list has Display Rules, Note and Shortcode columns, the template type shown next to each title, and a dropdown to filter by type.

Was this article helpful?