Support

Account

Home Forums Front-end Issues ACF Form Allow Script Tags for a Specific Field

Helping

ACF Form Allow Script Tags for a Specific Field

  • I have a textarea in ACF for my footer scripts. The issue I am having is within acf_form, basically if I try to enter <script> tags, they are getting stripped when I save the settings.

    For example, the following code:

    <script>
    console.log('foo'); 
    </script>

    Will become the following after saving:

    console.log('foo');

    Within WP-Admin, the <script> tags are not being stripped, this is only happening within acf_form on the frontend.

    Is there a way to allow these types of tags on the frontend for a particular field?

    Thanks in advance!

  • No, this cannot be done for one field, you would need to allow scripts in all fields as described in this document https://www.advancedcustomfields.com/resources/html-escaping/

    It might be possible to do this using an acf/save_post action with a priority of < 10 so that it runs before ACF saves the values.

    In this action you would need to get the submitted value from $_POST[‘acf’], you would need to save this value by bypassing ACF entirely by using WP meta functions and then delete the value from $_POST[‘acf’].

    However, this would only let you save the value, ACF will still not display the value on the front end to be edited after save without allowing script tags to be shown as I mentioned at the beginning. The only way to completely bypass wp_kses without allowing scripts in every field is to use a field that is not created by or managed by ACF. This might be possible by inserting a form field that you deal with yourself in an acf/save_post action by using either the “html_before_fields” or the “html_after_fields” arguments for acf_form().

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.