Support

Account

Home Forums Feature Requests Custom body class setting for WYSIWYG fields Reply To: Custom body class setting for WYSIWYG fields

  • I’ve had another look at the ACF WYSIWYG Styling plugin and also the acf docs and made a slight tweak to the code used in that plugin and I’m getting the classes added to my WYSIWYG’s again:

    
    function acf_plugin_wysiwyg_styling() { ?>
    	<script>
            (function($) {
                acf.add_filter('wysiwyg_tinymce_settings', function(mceInit, id, $field) {
                    var fieldKey = $field.data('key');
                    var fieldName = $field.data('name');
                    var flexContentName = $field.parents('[data-type="flexible_content"]').first().data('name');
                    var layoutName = $field.parents('[data-layout]').first().data('layout');
    
                    mceInit.body_class += " acf-field-key-" + fieldKey;
                    mceInit.body_class += " acf-field-name-" + fieldName;
                    if (flexContentName) {
                        mceInit.body_class += " acf-flex-name-" + flexContentName;
                    }
                    if (layoutName) {
                        mceInit.body_class += " acf-layout-" + layoutName;
                    }
                    return mceInit;
                });
    
            })(jQuery);
        </script>
    <?php
    }
    add_action('acf/input/admin_footer', 'acf_plugin_wysiwyg_styling');