Creation custom widget for WPBakery. Code example open

Creation custom widget for WPBakery. Code example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators

! Enable support for custom post types in the admin panel in the tab WPBakery Page Builder.

Documentation and list of available fields – https://kb.wpbakery.com/docs/inner-api/vc_map/

<?php

class myVCshortcode {

    function __construct(){
        add_action('init', array($this, 'create_shortcode'), 1000);
        add_shortcode('vcshortcode1', array($this, 'render_shortcode'));
    }

    public function create_shortcode() {
        
        if(!defined('WPB_VC_VISION')) {
           return; 
        }
       
        if(function_exist('vc_map')) {
        vc_map(array(
            'name' => 'Shortcode1',
            'base' => 'vcshortcode1',
            'description' => '',
            'category' => 'MyCategory',
            'params' => array(
                array(
                    'type' => 'textfield',
                    'heading' => 'Text',
                    'param_name' => 'text',
                    'value' => '',
                    'description' => 'Insert Text',
                ),
                array(
                    'type' => 'textarea_html',
                    'heading' => 'Description',
                    'param_name' => 'content',
                    'value' => '',
                    'description' => 'Insert Text',
                ),
                array(
                    'type' => 'textarea_html',
                    'heading' => 'Description',
                    'param_name' => 'content',
                    'value' => '',
                    'description' => 'Insert Description',
                )
            )
        ));
     }

    }

    public function render_shortcode($atts, $content, $tag) {
        //Front part shortcode
        $atts = (shortcode_atts(array(
            'text' => '',
        ),
        $atts));

        $title = $atts['text'];
        $content = wpb_js_remove_wpautop($content, true);

        $result = '';
        $result .= '<h2>' . $title . '</h2>';
        $result .= '<div class="content_box">' . $content . '</div>';

        return $result;

    }
}

new myVCshortcode();

0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation