1. Home
  2. Docs
  3. Inner API
  4. vc_add_default_templates()

vc_add_default_templates()

SINCE 4.3

To add more predefined templates to the WPBakery Page Builder (formerly Visual Composer) 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 (formerly Visual Composer) 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 (formerly Visual Composer).

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']    = <<<CONTENT
        [vc_row][vc_column width="1/2"][vc_single_image border_color="grey" img_link_target="_self"][vc_column_text]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.[/vc_column_text][/vc_column][vc_column width="1/2"][vc_message color="alert-info" style="rounded"]I am message box. Click edit button to change this text.[/vc_message][/vc_column][/vc_row]
CONTENT;
  
    vc_add_default_templates( $data );
}
?>

 

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
        [vc_row][vc_column width="1/2"][vc_single_image border_color="grey" img_link_target="_self"][vc_column_text]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.[/vc_column_text][/vc_column][vc_column width="1/2"][vc_message color="alert-info" style="rounded"]I am message box. Click edit button to change this text.[/vc_message][/vc_column][/vc_row]
CONTENT;
 
    array_unshift( $data, $template );
    return $data;
}
?>