Support

Account

Home Forums Backend Issues (wp-admin) Resrict valid formats in WYSIWYG editor

Solved

Resrict valid formats in WYSIWYG editor

  • Hi all,

    Is there any option to restrict the format (HTML codes) that is saved within the visual editor in ACF?

    I already restricted the Toolbar to a very limited set of formatting options. However, any kind of annoying formats can be accidentally introduced by copy-pasting formatted text from some where else.
    The original TinyMCE has the option extended_valid_elements, that can define valid HTML markup.

    Is it possible to define such an option in AFC as well?

  • Dear all,

    After sleeping some nights over this issue, I looked again at the acf JS code and suddenly found the wysiwyg_tinymce_settings filter. This helped me to modify the input fo the tinymce.init() call. My solution is:

    
    function my_acf_input_admin_footer() {
        ?>
        <script type="text/javascript">
            acf.add_filter('wysiwyg_tinymce_settings', function( mceInit, id, $field ){
                mceInit.valid_elements = 'p,strong,em,del,span[style="text-decoration: underline;"]';
                return mceInit;
    
            });
        </script>
        <?php
    }
    
    add_action('acf/input/admin_footer', 'my_acf_input_admin_footer');
    

    This restricts the editor to only use b, i, del and underlining.

    Now I’m happy again 🙂

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.