Skip to content

Page Builder Template Stack

Pavel Korotenko edited this page Jun 21, 2017 · 6 revisions

Page builder templates can be loaded from other sources outside of the theme. If you develop a plugin and want to include support for Page Builder you can supply Page Builder template parts from your plugin. There is also a template hierarchy when you add a location to the template stack. Page Builder will look in the order below to try and locate your registered template parts.

  • child theme /pagebuilder
  • parent theme /pagebuilder
  • plugin template stack locations
  • simple page builder plugin

To override a Page Builder template part in a plugin you would want to copy that template part to your active theme and put the file into a folder "pagebuilder". Page Builder looks into the pagebuilder folder to try and locate the template parts you choose in the admin.

Initializing Page Builder

To use the functions to add a location to the template stack you need to hook to "spb_init". Best method is to load a file on "spb_init" that contains the Page Builder code.

Example Loader Function:

function my_load_func() {
    require_once( plugin_dir_path( __FILE__ ) . 'inc/pagebuilder.php' );
}
add_action( 'spb_init', 'my_load_func' );

Registering Page Builder Template Location

In our file hooked to "spb_init" we simply need to add a call back function to "spb_register_template_stack()". This callback function is added to an array of methods that the template stack runs to return the paths to the location of your plugins template part folder.

Example Template Stack Function:

function my_plugin_get_template_part_dir() {
    return '/srv/www/yoursite/wp-content/plugins/WDS-spb-register-template-parts/parts/';
}
spb_register_template_stack( 'my_plugin_get_template_part_dir', 10 );
  • note: the callback function needs to be located outside of a class to be available.