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?

  • 1
    the trick with this is to only do edittion on the "text" tab and never switch to "visual" tab – Temani Afif Dec 25 '17 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 Sep 29 '18 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 Sep 29 '18 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 Sep 29 '18 at 10:54

You need to change the type from textarea to textarea_raw_html:

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'] ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.