This article shows you how to display the output of the elements which you have registered via
add_map() and built-in admin.
Notice: From version 2.3 all elements will be created as shortcode automatically. You only need to create the template file for your shortcode ( wp-content/themes/yourtheme/kingcomposer/
{your_element_name}.php ).
You also can change the default template folder, check this article for setting template path
http://docs.kingcomposer.com/set-template-path/
1. Native Shortcodes ( Default KC Shortcodes ).
You can find all these highest-priority files in the folder:
// You can find all native shortcode's template in this folder
/wp-content/plugins/kingcomposer/shortcodes/
You can set the folder path for your own template to overwrite. Please read more
Set Template Path.
With activated theme, the default path is:
/wp-content/themes/{active_theme}/kingcomposer/. You can copy template files from
/wp-content/plugins/kingcomposer/shortcodes/ to this folder and edit them. Or you can use the method
Set Template Path to set your own folder.
With a shortcode of 3rd-party plugins or templates, you must use the method
Set Template Path to set your folder path for shortcode templates.
How to get parameter values?
// Example with shortcode kc_single_image
// Copy the file: /wp-content/plugins/kingcomposer/shortcodes/kc_single_image.php
// Paste & edit file in: /wp-content/themes/{your-activated-theme}/kingcomposer/kc_single_image.php
// All param values of shortcode will be passed on through the variable $atts
print_r( $atts );
// The shortcode container such as [name] ___the_content___ [/name]
// The shortcode content will be returned through the variable $content
2. External Shortcodes.
All newly-registered shortcodes of kingcomposer work the same as Wordpress ones. Please read more about
add_shortcode()
NOTICE: If your shortcode has been registered by function
add_shortcode(), Some of fields' attributes data will not be decoded such as 'editor', 'textarea', 'group'. You must run base64_decode() before use.
Example:
add_map(
array(
'my_element' => array(
'name' => 'My Element',
'description' => __('My sample element', 'kingcomposer'),
'icon' => 'sl-paper-plane',
'category' => 'Content',
'params' => array(
array(
'name' => 'param_1',
'label' => 'Param Sample',
'type' => 'text',
)
)
)
)
);
add_shortcode( 'my_element', 'my_element_PHP_Function' );
function my_element_PHP_Function( $atts ){
// Your code here
}
?>