vc_add_param()
To add new parameter to existing content element you can use vc_add_param() function. List of available parameters.
Available SINCE 4.3
<?php vc_add_param( $shortcode, $attributes ); ?>
Parameters
$shortcode
- Type - String
- Description - Shortcode base. For
[my_shortcode]shortcode base ismy_shortcode. For default "Message box" element, base isvc_message. - Example:
$shortcode = 'vc_message';
$attributes
- Type - Array
- Description - Array should be defined according to
vc_map()available options. - Example:
$attributes = [
'type' => 'textfield',
'heading' => __( 'Custom Heading', 'my-text-domain' ),
'param_name' => 'custom_param',
'value' => '',
'description' => __( 'This is a custom parameter for the vc_row shortcode.', 'my-text-domain' ),
];
Example
How to add new attribute to the default "Message box" content element:
<?php
$attributes = [
'type' => 'dropdown',
'heading' => "Style",
'param_name' => 'style',
'value' => [ "one", "two", "three" ],
'description' => __( "New style attribute", "my-text-domain" )
];
vc_add_param( 'vc_message', $attributes ); // Note: 'vc_message' was used as a base for "Message box" element
?>
Code explanation:
- First we create array which "describes" new attribute that should be added to "Message box" element. Note: during the initial
vc_map()function callvc_messagewas used as a base attribute, base is required to properly "target" function call - Then we call
vc_add_param()function with new attribute and base