本文介绍了将 Visual Composer 短代码渲染到页面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试将 echo 可视化编辑器 shortcodes 放到页面上.

I am trying to echo visual composer shortcodes onto a page.

我已经尝试了以下两种方法,但它们不起作用:

I've tried both methods below, but they don't work:

functions.php:

方法一

/*
 * add shortcode file
 */
function include_file($atts) {
    $a = shortcode_atts( array(
        'slug' => 'NULL',
    ), $atts );

    if($slug != 'NULL'){
        ob_start();
        get_template_part($a['slug']);
        return ob_get_clean();
    }
}
add_shortcode('include', 'include_file');

方法二

function someshortocode_callback( $atts = array(), $content = null ) {

    $output = "[vc_section full_width=\"stretch_row\" css=\".vc_custom_1499155244783{padding-top: 8vh !important;padding-bottom: 5vh !important;background-color: #f7f7f7 !important;}\"][vc_row 0=\"\"][vc_column offset=\"vc_col-lg-offset-3 vc_col-lg-6 vc_col-md-offset-3 vc_col-md-6\"][/vc_column][/vc_row][/vc_section]";
    return $output;
}
add_shortcode('someshortocode', 'someshortocode_callback');

file_rendering_vc_shortcodes.php:

方法一

<?php if ( is_plugin_active( 'js_composer/js_composer.php' ) ) {
    wc_print_notice('js_composer plugin ACTIVE', 'notice');
    echo do_shortcode('[include slug="vc_templates/shop-page"]');
}; ?>

结果

  • js_composer 插件正在运行
  • 短代码在带有括号的页面上

方法二

<?php $post = get_post();

if ( $post && preg_match( '/vc_row/', $post->post_content ) ) {
// Visual composer works on current page/post
    wc_print_notice('VC ON', 'notice');
    echo add_shortcode('someshortocode', 'someshortocode_callback');
} else {
    wc_print_notice('VC OFF', 'notice');
    //echo do_shortcode('[include slug="vc_templates/shop-page"]');
}; ?>

结果

  • VC OFF(显然,因为短代码中的 vc_row 不存在)
  • 页面上没有简码

shop-page.php

<?php
/**
Template Name:  Shop Page in theme
Preview Image:  #
Descriptions:   #
 * [vc_row][vc_column][/vc_column][/vc_row]
 */
?>
[vc_section full_width="stretch_row" css=".vc_custom_1499155244783{padding-top: 8vh !important;padding-bottom: 5vh !important;background-color: #f7f7f7 !important;}"][vc_row 0=""][vc_column offset="vc_col-lg-offset-3 vc_col-lg-6 vc_col-md-offset-3 vc_col-md-6"][/vc_column][/vc_row][/vc_section]

是否可以在页面上渲染vc shortcodes,如果可以,如何实现?

Is it possible to render vc shortcodes on page, and if so, how is it done?

推荐答案

使用:

WPBMap::addAllMappedShortcodes();

然后像往常一样do_shortcode($content);

简而言之,页面构建器由于性能原因不会注册短代码,除非它不是必需的.

In short, page builder due to performance doesn't register shortcodes unless it isn't required.

如果您的元素是通过vc_mapvc_lean_map 注册的,则无需使用add_shortcode 函数,您只需使用WPBMap::addAllMappedShortcodes(); 它会在渲染过程中调用一个简码类回调,然后调用简码模板.

If your element is registered by vc_map or vc_lean_map then no need to use add_shortcode function, you can do everything just by using WPBMap::addAllMappedShortcodes(); it is will call an shortcode class callback during the rendering process and then shortcode template.

这篇关于将 Visual Composer 短代码渲染到页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 13:00