devnoob devnoob - 1 year ago 259
PHP Question

Add custom font icons to visual composer

I'm adding new icons to the Visual Composer iconbox in wordpress but i get the following 2 errors anyone know how to fix? Below is the code in my functions.php file

// Add new custom font to Font Family selection in icon box module
function myprefix_add_new_icon_set_to_iconbox( ) {
$param = WPBMap::getParam( 'vcex_icon_box', 'icon_type' );
$param['value'][__( 'CUSTOM ICONS NAME', 'total' )] = 'my_custom_icons';
vc_update_shortcode_param( 'vcex_icon_box', $param );
add_filter( 'init', 'myprefix_add_new_icon_set_to_iconbox', 40 );

// Add font picker setting to icon box module when you select your font family from the dropdown
function myprefix_add_font_picker() {
vc_add_param( 'vcex_icon_box', array(
'type' => 'iconpicker',
'heading' => esc_html__( 'Icon', 'total' ),
'param_name' => 'my_custom_icons',
'settings' => array(
'emptyIcon' => true,
'type' => 'my_custom_icons',
'iconsPerPage' => 20,
'dependency' => array(
'element' => 'icon_type',
'value' => 'my_custom_icons',
'group' => esc_html__( 'Icon', 'total' ),
add_filter( 'vc_after_init', 'myprefix_add_font_picker', 40 );

// Add array of your fonts so they can be displayed in the font selector
function my_icon_array() {
return array(
'bg-icon-twitter' => 'Twitter',
'bg-icon-user' => 'User'
add_filter( 'vc_iconpicker-type-my_custom_icons', 'my_icon_array' );


Wrong name for shortcode:vcex_icon_box. Name required in
on line 472


Cannot use a scalar value as an array in
on line 367

Answer Source

Error 1 is caused by the fact you don't have a shortcode in your installation called "vcex_icon_box". Try "vc_icon" instead.

Also, if you use vc_icon, you will need to change the dependency element to type and not icon_type.

For error 2, WPBMap::getParam( 'vcex_icon_box', 'icon_type' ); is returning a scalar value, which you can then treat it like an array.

As a debug tip, its a good idea to test the outputs of functions so you understand what you are getting.

The VC documentation is also not the greatest.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download