
How to create Custom Shortcode in Avada Fusion Core Plugin
- January 27, 2016
- Leave a comment
Fusion Core plugin is a companion plugin required to use Avada Theme. It can be extended by creating shortcodes. You have to create another plugin to incorporate fusion core class “FusionCore_Plugin” in it.
At first, you need to remove fusion_shortcode_popup function from Parent plugin and then add this “popup” function in Child class of your custom plugin:
1 2 |
remove_action('wp_ajax_fusion_shortcodes_popup', array('FusionCore_Plugin', 'popup'), 10); add_action('wp_ajax_fusion_shortcodes_popup', array(&$this, 'popup'), 10); |
Now add fusion-sc.php file in this function where shortcode array needs to be added:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
if( ! class_exists( 'presstigers_FusionCore_Plugin') && class_exists('FusionCore_Plugin') ) { class presstigers_FusionCore_Plugin extends FusionCore_Plugin { /** * Initialize the plugin by setting localization and loading public scripts * and styles. * * @since 1.0.0 */ function __construct() { define('CUSTOM_SHORTCODES_URI', plugin_dir_url( __FILE__ ) . 'includes'); define('CUSTOM_SHORTCODES_DIR', plugin_dir_path( __FILE__ ) .'includes'); remove_action('wp_ajax_fusion_shortcodes_popup', array('FusionCore_Plugin', 'popup'), 10); add_action('wp_ajax_fusion_shortcodes_popup', array(&$this, 'popup'), 10); } /** * Popup function which will show shortcode options in thickbox. * * @return void */ function popup() { require_once( CUSTOM_SHORTCODES_DIR . '/fusion-sc.php' ); die(); } } new presstigers_FusionCore_Plugin(); } |
In this “fusion-sc.php” file, you have to add a particular code that will be displayed in popup by clicking on shortcode icon in post visual editor. The shortcode name array will be displayed in the dropdown:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
$select_shortcode = array( 'select' => 'Choose a Shortcode', 'alert' => 'Alert', 'blog' => 'Blog', 'button' => 'Button', 'checklist' => 'Checklist', //'clientslider' => 'Client Slider', //'code' => 'Code Block', 'columns' => 'Columns', 'contentboxes' => 'Content Boxes', 'countersbox' => 'Counters Box', 'counterscircle' => 'Counters Circle', 'dropcap' => 'Dropcap', 'flipboxes' => 'Flip Boxes', //'fontawesome' => 'Font Awesome', 'fusionslider' => 'Fusion Slider', 'fullwidth' => 'Full Width Container', 'googlemap' => 'Google Map', 'highlight' => 'Highlight', 'heading' => 'heading', 'imageframe' => 'Image Frame', 'lightbox' => 'Lightbox', 'menuanchor' => 'Menu Anchor', 'modal' => 'Modal', 'modaltextlink' => 'Modal Text Link', 'onepagetextlink' => 'One Page Text Link', 'person' => 'Person', 'popover' => 'Popover', 'postslider' => 'Post Slider', 'pricingtable' => 'Pricing Table', 'progressbar' => 'Progress Bar', 'recentposts' => 'Recent Posts', 'recentworks' => 'Recent Works', 'hubspot' => 'Presstigers Hubspot Form', 'pt_content_button' => ' Presstigers Content section with button', 'pt_benchmark' => ' Presstigers Benchmark', 'pt_tweets' => ' Presstigers Tweets', 'sectionseparator' => 'Section Separator', 'separator' => 'Separator', 'sharingbox' => 'Sharing Box', 'slider' => 'Slider', 'sociallinks' => 'Social Links', 'soundcloud' => 'SoundCloud', 'table' => 'Table', 'tabs' => 'Tabs', 'taglinebox' => 'Tagline Box', 'testimonials' => 'Testimonials', 'title' => 'Title', 'toggles' => 'Toggles', 'tooltip' => 'Tooltip', 'vimeo' => 'Vimeo', 'woofeatured' => 'Woocommerce Featured Products Slider', 'wooproducts' => 'Woocommerce Products Slider', 'youtube' => 'Youtube' ); |
Now you can add shortcode fields array with a global variable “$fusion_shortcodes”. By using this variable, shortcode fields will be added:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
global $fusion_shortcodes; /*-----------------------------------------------------------------------------------*/ /* Content with button Config /*-----------------------------------------------------------------------------------*/ $fusion_shortcodes['pt_content_button'] = array( 'no_preview' => true, 'params' => array( 'image' => array( 'std' => '', 'type' => 'uploader', 'label' => __( 'Image ', 'fusion-core' ), 'desc' => __( 'custom Image', 'fusion-core') ), 'title' => array( 'std' => '', 'type' => 'text', 'label' => __( 'Title', 'fusion-core' ), 'desc' => __( 'Section Title', 'fusion-core') ), 'short_description' => array( 'std' => '', 'type' => 'textarea', 'label' => __( 'Short Description', 'fusion-core' ), 'desc' => __( '', 'fusion-core') ), 'button_text' => array( 'std' => '', 'type' => 'text', 'label' => __( 'Button Text', 'fusion-core' ), 'desc' => __( 'Button Text', 'fusion-core') ), 'button_link' => array( 'std' => '', 'type' => 'text', 'label' => __( 'Button Link', 'fusion-core' ), 'desc' => __( 'Button Link', 'fusion-core') ), 'class' => array( 'std' => '', 'type' => 'text', 'label' => __( 'CSS Class', 'fusion-core' ), 'desc' => __( 'Add a class to the wrapping HTML element.', 'fusion-core') ), 'id' => array( 'std' => '', 'type' => 'text', 'label' => __( 'CSS ID', 'fusion-core' ), 'desc' => __( 'Add an ID to the wrapping HTML element.', 'fusion-core') ), ), 'shortcode' => '[pt_content_button image={{image}} title="{{title}}" button_text="{{button_text}}" button_link="{{button_link}}" class="{{class}}" id="{{id}}"]{{short_description}}[/pt_content_button]', 'popup_title' => __( 'Content with button Shortcode', 'fusion-core' ) ); |
By adding shortcode in the visual editor, you can render shortcode by using your own function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function pt_content_button_shortcode_render($atts, $content = null){ extract(shortcode_atts(array( 'class' => '', 'id' => '', 'title' => '', 'image' => '', 'button_text' => '', 'button_link' => '', 'textcolor' => '#fff', ), $atts)); return; } add_shortcode('pt_content_button', 'pt content_button_shortcode_render'); |
This does not work…
Dear Miguel,
These are workable code snippets and will add a shortcode in text editor of “Avada” shortcodes as dropdown. Please take a look on following screenshot’s links for your reference:
http://prntscr.com/busr6z
http://prntscr.com/busrh8
Let us know if we can help you further.
Thanks,
—
Yours truly,
Sehrish Iftikhar
Level lll Support
Also not working for me
Hello Alex,
Have you visited the above listed links for screenshots?
Thanks & Regards,
—
Sehrish Iftikhar | WP Plugin Developer
Email: support@presstigers.com
I’m working on getting this going but right away, in case these folks are just cutting and pasting code, I’m noticing your add_shortcode() fx call is missing an underscore in your custom function title. 😉 Thanks for sharing.
Hello Caroline,
These code snippets have been taken from workable development directory. So, we are not experiencing any missing underscore issue.
Regards,
—
Sehrish Iftikhar | WP Plugin Developer
Email: support@presstigers.com
The Problem is, that your html entities in the code blocks of your theme are escaped.
E.G.:
‘select’ => ‘Choose a Shortcode’,
Should be:
‘select’ => ‘Choose a Shortcode’,
When you change all escaped html entities, the code should be running.
Cheers,
Marcel
😀
The escaped greater than arrow was rendered correctly in my comment, so it doesn’t make sense.
You have to change “=>” to “=>”.
Hope it’s rendered right now.
Hello Marcel,
Thank you so much for pointing out the issue. We have fixed the issue at our end now.
Let us know if you need any assistance from us.
Regards,
—
Abdullah | WP Plugin Developer
Email: support@presstigers.com