SINCE 4.3
To add more predefined templates to the WPBakery Page Builder interface call vc_add_default_templates() function in your function.php file. Predefined templates are available since WPBakery Page Builder 4.3 version. Note: vc_add_default_templates() should be hooked in vc_load_default_templates_action action.
<?php vc_add_default_templates( $data ); ?>
Params
Param name | Type | Description |
---|---|---|
$data | Array | Information about your new predefined template |
Examples
Starting from WPBakery Page Builder version 4.3 you can select from predefined started templates and you can modify that list to add more custom templates. For example within your theme or third party addon for WPBakery Page Builder .
Add new custom template
Hook in vc_load_default_templates_action to add your custom template to the list.
<?php add_action( 'vc_load_default_templates_action','my_custom_template_for_vc' ); // Hook in function my_custom_template_for_vc() { $data = array(); // Create new array $data['name'] = __( 'Custom template', 'my-text-domain' ); // Assign name for your custom template $data['weight'] = 0; // Weight of your template in the template list $data['image_path'] = preg_replace( '/\s/', '%20', plugins_url( 'images/custom_template_thumbnail.jpg', __FILE__ ) ); // Always use preg replace to be sure that "space" will not break logic. Thumbnail should have this dimensions: 114x154px $data['custom_class'] = 'custom_template_for_vc_custom_template'; // CSS class name $data['content'] = <<<CONTENTCONTENT; vc_add_default_templates( $data ); } ?>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
Modify default templates
To modify default templates list you can use vc_load_default_templates hook and filter/modify array which stores default templates in it.
<?php add_filter( 'vc_load_default_templates', 'my_custom_template_modify_array' ); // Hook in function my_custom_template_modify_array( $data ) { return array(); // This will remove all default templates. Basically you should use native PHP functions to modify existing array and then return it. } ?>
Place your custom template to the first position
Here’s a quick example how you can place your new custom template to the first position in the array.
<?php
add_filter( 'vc_load_default_templates', 'my_custom_template_at_first_position' ); // Hook in
function my_custom_template_at_first_position( $data ) {
$template = array();
$template['name'] = __( 'Custom template', 'my-text-domain' ); // Assign name for your custom template
$template['image_path'] = preg_replace( '/\s/', '%20', plugins_url( 'images/custom_template_thumbnail.jpg', __FILE__ ) ); // Always use preg replace to be sure that "space" will not break logic. Thumbnail should have this dimensions: 114x154px.
$template['custom_class'] = 'custom_template_for_vc_custom_template'; // CSS class name
$template['content'] = <<<CONTENT
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
CONTENT;
array_unshift( $data, $template );
return $data;
}
?>