You can add any number of custom addons in WP Page Builder from your WordPress theme or plugin. You just have to add a filter and include your addon Class name using this filter-
add_filter( 'wppb_available_addons', 'prefix_custom_addon_include' );
if ( ! function_exists('prefix_custom_addon_include')){
function prefix_custom_addon_include($addons){
$addons[] = 'Custom_Addon';
// Add Other Custom Addon class name in here, at a time.
return $addons;
}
}
You can check our plugins shortcode inside in here plugins_directory/addons
Here is a sample addon code-
get_name()
must be unique and without spaceget_title()
You can use space and it will be display as Addon nameget_icon()
support FontAwesome 4 and WPPB default icon.get_category_name()
If want to show the addon in a specific category then use this functionget_settings()
You can use any field type in here.render()
here is a frontend output. If you don't usegetTemplate()
then live editing comes from AJAX request viarender()
function.getTemplate()
Speedup your frontend editing. It's using Lodash templating. So follow lodash templating documentation.get_enqueue_script()
andget_enqueue_style()
stands for specific script and style for specific addons. If the addon remains on the page then the style or script add on the page. You just have towp_register_script
andwp_register_style
anywhere in your theme or plugins (Don notwp_enqueue_script
orwp_enqueue_style
).
class Custom_Addon{
public function get_name(){
return 'checkit';
}
public function get_title(){
return 'Checkit';
}
public function get_icon() {
return 'wppb-font-trash';
}
public function get_category_name(){
return 'Addon Category';
}
/*
public function get_enqueue_script(){
return array( 'script-name' );
}
public function get_enqueue_style(){
return array( 'style-name' );
}
*/
// Textarea Settings Fields
public function get_settings() {
$settings = array(
'custom_addon_textarea' => array(
'type' => 'textarea',
'title' => 'Textarea Title',
'placeholder' => 'Textarea Placeholder',
'std' => 'Textarea Default'
),
);
return $settings;
}
public function render($data = null){
$settings = $data['settings'];
return '<div class="wrapper">TextArea Output:'.$settings['custom_addon_textarea'].'</div>';
}
// headline Template
public function getTemplate(){
return '<# if(data.custom_addon_textarea){ #>
<div class="sample-number1">DATA:{{data.custom_addon_textarea}}</div>
<# } #>';
}
}