最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - How to allow HTML tags into WP Bakery (formerly Visual Composer) `textfield` parameter

programmeradmin1浏览0评论

While writing a custom element for WC Bakery (formerly Visual Composer) I've discovered that the HTML tags are being stripped from the textfield parameter type. It's sanitizing the textfield value by default.

I could not find a way to disable the textfield sanitization.

How can I allow HTML tags to be entered into this field?

While writing a custom element for WC Bakery (formerly Visual Composer) I've discovered that the HTML tags are being stripped from the textfield parameter type. It's sanitizing the textfield value by default.

I could not find a way to disable the textfield sanitization.

How can I allow HTML tags to be entered into this field?

Share Improve this question edited Oct 1, 2018 at 8:18 Eh Jewel asked Dec 25, 2017 at 7:25 Eh JewelEh Jewel 8553 gold badges14 silver badges29 bronze badges 4
  • 2 the trick with this is to only do edittion on the "text" tab and never switch to "visual" tab – Temani Afif Commented Dec 25, 2017 at 7:45
  • @TemaniAfif thats not related to this question, its not written very clearly but its about writing custom elements for Visual Composer (now WP Bakery), which just has a plain text area but if you try to add complex html into it then it gets stripped. Seems to work for simple stuff like strong though. – rtpHarry Commented Sep 29, 2018 at 9:23
  • @rtpHarry I know this very well :) and it's related because the solution I use everyday is to consider the text tab where you can add code like want but if you switch to visual tab some of the code will disappear so I never switch to visual tab ;) – Temani Afif Commented Sep 29, 2018 at 9:30
  • @TemaniAfif yes you are correct that you shouldn't swap the text tab to visual or it will mess up your markup -- but thats not whats being asked about here. Op is asking about the Visual Composer textfield param type which I linked to in my answer below. It's front end is not the tinymce based editor, it is a simple, plain textarea tag and it will strip the html in some situations. – rtpHarry Commented Sep 29, 2018 at 10:54
Add a comment  | 

2 Answers 2

Reset to default 4

You need to change the type from textarea to textarea_raw_html:

  • https://kb.wpbakery/docs/inner-api/vc_map/

Under the section "Available type values" it says:

textarea_raw_html: Text area, its content will be coded into base64 (this allows you to store raw js or raw html code)

Although I'm not sure why they can base64 encode the output from this but not the textarea_html box with its nice formatting - an annoying limitation.

UPDATE It looks like you have to jump through some hoops when you switch to the textarea_raw_html param type.

To use the value you need to manually decode it with:

$atts['some_param'] =  rawurldecode( base64_decode( $atts['some_param'] ) );

If you pass the vc_map param as param_name = 'content' the html wont get stripped off. The problem is you can only put one content.

array(
                'type' => 'textarea',
                'heading' => esc_html__( 'Texto', 'bauhaus' ),
                'param_name' => 'content',
                'holder' => 'div'
            ),
add_shortcode( 'custom_bloque_informativo', 'custom_bloque_informativo_func' );
function custom_bloque_informativo_func( $atts, $content ) {
    ob_start();
}
发布评论

评论列表(0)

  1. 暂无评论