如何将 HTML 属性添加到行(WP Bakery Visual Composer)?

编程入门 行业动态 更新时间:2024-10-28 10:24:54
本文介绍了如何将 HTML 属性添加到行(WP Bakery Visual Composer)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我试图通过文档化的函数 vc_add_param() 以这种方式向 Visual Composer 中的行添加一个 ID 属性:

I am trying to add an ID attribute to row in Visual Composer via documented function vc_add_param() in such a way:

$attributes = array(
 'type' => 'textfield',
 'heading' => "HTML ID",
 'param_name' => 'el_id',
 'value' => '',
 'description' => __( "Assign an ID to the row", "discprofile" )
);
vc_add_param( 'vc_row', $attributes );

当我编辑一行时会出现 ID 字段.我设置了一个值,保存它,保存页面,查看它,但对前端没有影响.一行仍然没有 ID 属性.

ID field appears when I edit a row. I set a value, save it, save page, view it, but there is no affect to frontend. A row still has no ID attribute.

我也试过使用 'param_name' =>'id''param_name' =>'element_id',是一样的.怎么了?

I've also tried use 'param_name' => 'id' and 'param_name' => 'element_id', it was the same. What is wrong?

推荐答案

解决方案:

我们必须重新映射短代码并更改其模板以添加其他参数.

We have to remap a shortcode and change its template to add additional parameters.

所以,就我而言:

// Add custom row options

    function change_vc_rows() {

        // Add parameters we want
        vc_add_param('vc_row', array(
            'type' => 'textfield',
            'heading' => "HTML ID",
            'param_name' => 'element_id',
            'value' => '',
            'description' => __("Assign an ID to the row", "discprofile")
        ));

        // Update 'vc_row' to include custom vc_row template and remap shortcode
        $new_map = vc_map_update( 'vc_row', array('html_template' => locate_template('templates/vc_row.php')) );

        // Remove default vc_row
        vc_remove_element('vc_row');

        // Remap shortcode with custom template
        vc_map($new_map['vc_row']);
    }

    // Include our function when all wordpress stuff is loaded
    add_action( 'wp_loaded', 'change_vc_rows' );

我们包含了模板/vc_rows.php 文件.它是行模板文件,从 plugins/js_composer/include/templates/shortcodes/vc_rows.php 复制并进行了一些更改.这是:

We included templates/vc_rows.php file. It is the row template file, copied from plugins/js_composer/include/templates/shortcodes/vc_rows.php with some changes. Here it is:

<?php
/** @var $this WPBakeryShortCode_VC_Row */
// $element_id was added to output
$output = $element_id = $el_class = $bg_image = $bg_color = $bg_image_repeat = $font_color = $padding = $margin_bottom = $css = $full_width = '';
extract( shortcode_atts( array(
    // added element_id attribute
    'element_id' => '',
    'el_class' => '',
    'bg_image' => '',
    'bg_color' => '',
    'bg_image_repeat' => '',
    'font_color' => '',
    'padding' => '',
    'margin_bottom' => '',
    'full_width' => false,
    'css' => '',
), $atts ) );

// wp_enqueue_style( 'js_composer_front' );
wp_enqueue_script( 'wpb_composer_front_js' );
// wp_enqueue_style('js_composer_custom_css');

$el_class = $this->getExtraClass( $el_class );

$css_class = apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'vc_row wpb_row ' . ( $this->settings( 'base' ) === 'vc_row_inner' ? 'vc_inner ' : '' ) . get_row_css_class() . $el_class . vc_shortcode_custom_css_class( $css, ' ' ), $this->settings['base'], $atts );

$style = $this->buildStyle( $bg_image, $bg_color, $bg_image_repeat, $font_color, $padding, $margin_bottom );
?>

<!-- Added an ID attribute where we echo our $element_id variable -->
<div <?php
    ?>class="<?php echo esc_attr( $css_class ); ?><?php if ( $full_width == 'stretch_row_content_no_spaces' ): echo ' vc_row-no-padding'; endif; ?>" id="<?php echo $element_id; ?>" <?php if ( ! empty( $full_width ) ) {
    echo ' data-vc-full-width="true"';
    if ( $full_width == 'stretch_row_content' || $full_width == 'stretch_row_content_no_spaces' ) {
        echo ' data-vc-stretch-content="true"';
    }
} ?> <?php echo $style; ?>><?php
echo wpb_js_remove_wpautop( $content );
?></div><?php echo $this->endBlockComment( 'row' );
echo '<div class="vc_row-full-width"></div>';

这篇关于如何将 HTML 属性添加到行(WP Bakery Visual Composer)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 05:46:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1079985.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   属性   HTML   WP   Visual

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!