monakh2
3/17/2020 - 2:23 PM

add custom shortCode in the elements library of WPBakery

/* 
 *   Available type values
 *  https://kb.wpbakery.com/docs/inner-api/vc_map/
 * */
add_shortcode( 'testShortcode', 'testShortcode' );

function testShortcode( $atts = [], $content = null ) {
	extract( shortcode_atts( array(
		'icon' => '',
	), $atts, 'testShortcode' ) );

	$output = '<div class="test-shortcode">' . do_shortcode( $content ) . '</div>';
	$output .= '<span class="' . $atts['icon '] . '"></span>';

	return $output;
}

add_action( 'vc_before_init', 'testShortcodeWithVC' );
function testShortcodeWithVC() {
	vc_map( array(
		"name"     => __( "Test shortcode", "dali-deluxe" ),
		"base"     => "testShortcode",
		"class"    => "",
		"category" => __( "Dali-deluxe", "dali-deluxe" ),
//		'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
//		'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
		"params"   => array(
			array(
				"type"        => "textarea_html",
				"holder"      => "div",
				"class"       => "",
				"heading"     => __( "Текст под заголовком страницы", "dali-deluxe" ),
				"param_name"  => "content",
				"value"       => __( "Текст под заголовком", "dali-deluxe" ),
				"description" => __( "Введите текст", "dali-deluxe" )
			),
			array(
				'type'        => 'iconpicker',
				'heading'     => __( 'Icon', 'js_composer' ), /*Фраза из зарегистрированной библиотели перевода */
				'param_name'  => 'icon',
				'settings'    => array(
					'emptyIcon'    => false, /*default true, display an "EMPTY" icon?*/
					'type'         => 'dali',
					'iconsPerPage' => 50 /*default 100, how many icons per/page to display*/
				),
				'dependency'  => array(
					'element' => 'icon_type',
					'value'   => 'dali',
				),
				'description' => __( 'icon library: icon-dali', 'js_composer' ),
			),
		)
	) );
}