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');
Mmm yeah I was using the ACF WYSIWYG Styling plugin, but that is now only adding the class ‘acf-field-name-undefined’ to the wysiwyg iframe. The javascript solution above only gives me a javascript error in wordpress now as well.
Does anyone have a solution that works with the latest acf version?
Ah, lovely stuff – thats perfect John nice one.
Just thought about this too.. understand that its probably not the biggest priority feature, but would still be pretty useful if it did get incorporated at some time.
Thanks @delwinv for the plugin – very useful, would be great if this functionality could be added to the core plugin.
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 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.