Snippets: Insert Template Content via Theme Hooks

The following snippet shows you how you can insert a WPBakery template to your site via a hook, this is ideal for advanced usage where you may need to add custom conditionals so it doesn't show up on every page, however, if you are adding the template on every page you may want to instead use the theme's Custom Actions panel.

// Insert Templatera content after the header via the wpex_hook_header_after hook
add_action( 'wpex_hook_header_after', function() {

	// Change this to the templatera post ID you want to grab content from
	$template = 100;

	// Get Design options CSS for the template (fixes bug with wpbakery not rendering design options on archives)
	$custom_css = esc_attr( get_post_meta( $template, '_wpb_shortcodes_custom_css', true ) );

	if ( ! empty( $custom_css ) ) {

		$output .= '<style data-type="vc_shortcodes-custom-css">';

			$output .= function_exists( 'wpex_minify_css' ) ? wpex_minify_css( $custom_css ) : wp_strip_all_tags( $custom_css );

		$output .= '</style>';


	// Display template
	echo do_shortcode( '[templatera id="' . $template . '"]' );

} );
All PHP snippets should be added via a child theme's functions.php file.