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');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
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.