如何将自定义简码添加到WPBakery Visual Composer?

时间:2018-09-03 06:47:37

标签: php wordpress wordpress-shortcode

我正在尝试通过子主题为WPBakery简码实现自定义简码,我正在使用以下代码:

在我的function.php中

if ( function_exists( 'vc_set_shortcodes_templates_dir' ) ) {
            $dir = get_stylesheet_directory() . '/vc_templates';
            vc_set_shortcodes_templates_dir( $dir );
        }

if(function_exists('vc_map')){
vc_map( array(
    "name" => esc_html__("SK Empty Space","salih"),
    "base" => "sk_empty_space",
    "class" => "",
    "category" => esc_html__("SK", "salih"),
    "icon" => "",
    "params" => array(
        array(
            "type" => "textfield",
            "holder" => "div",
            "class" => "",
            "heading" => esc_html__("Space","salih"),
            "param_name" => "space",
            "value" => "",
            "description" => esc_html__('Enter empty space as margin in px', 'pexr')
        ),
        array(
            "type" => "textfield",
            "holder" => "div",
            "class" => "",
            "heading" => esc_html__("Extra class name","salih"),
            "param_name" => "el_class",
            "value" => "",
            "description" => esc_html__('If you wish to style particular content element differently, then use this field to add a class name and then refer to it in your css file.', 'salih')
        ),
        array(
            'type' => 'css_editor',
            'heading' => esc_html__( 'CSS box', 'salih' ),
            'param_name' => 'css',
            'group' => esc_html__( 'Design Options', 'salih' ),
        )
    )
) );

}

WPBakeryShortCode_sk_empty_space类扩展了WPBakeryShortCode {}

并在vc_templates文件夹sk_empty_space.php中是这样的:

    extract(shortcode_atts(array(
    'space' => '',
    'el_class' => '',
), $atts));

$class = array('');
$class[] = $el_class;

?>

<div class="clearfix"></div>
<div style="width: 100%; float: left; margin-bottom: <?php echo esc_attr( $space ); ?>;"></div>
<div class="clearfix"></div>

但是无论我做什么,似乎模板文件都无法使用该功能,我可以在前端看到如下通知:

  

注意:sk_empty_space短代码缺少模板文件。确保主题文件夹中有wp-content/themes/your_theme/vc_templates/sk_empty_space.php个文件。在D:\ Ampps \ www \ covenant.local \ wp-content \ plugins \ js_composer \ include \ classes \ shortcodes \ shortcodes.php中

我该如何解决?我在WPBakery文档中进行了搜索,根据该文档,上面的代码是正确的,在短代码之上我还缺少什么?

我在Child theme functions.php中使用上面的代码,在vc_templates文件夹中使用模板

0 个答案:

没有答案