You can pretty easily customize the advanced custom fields WYSIWYG toolbars globally, however doing so on a case-by-case basis needs to be done in JS since the editing experience is so dynamic.
This code is looking for a specific ACF field called step_text
and sets the WYSIWYG editor to only allow bold, italic and links.
add_action( 'acf/input/admin_footer', static function () { ?> <script type="text/javascript"> (function ( $ ) { acf .add_filter( 'wysiwyg_tinymce_settings', function( mceInit, id, field ) { if ( field.context.dataset.hasOwnProperty( 'type' ) && field.context.dataset.hasOwnProperty( 'name' ) && 'step_text' === field.context.dataset.name && 'wysiwyg' === field.context.dataset.type ) { console.dir(mceInit.toolbar1); mceInit.toolbar1 = 'bold,italic,link'; } return mceInit; } ) ; } )( jQuery ); </script> <?php } );
Update – 2021-02-12
This doesn’t seem to work universally. While working on another site, field.context
was not being sent and instead, field
appears to be (possibly) array-like. This fix was to use some different properties, and to also use a field key instead of name. Less optimal, but still not terrible.
add_action(
'acf/input/admin_footer',
static function () {
?>
<script type="text/javascript">
(function ($) {
acf
.add_filter(
'wysiwyg_tinymce_settings',
function (mceInit, id, field) {
if (field.data && typeof field.data === 'function') {
const key = field.data().key;
// Accreditation
if (key === 'field_5d07ad30d9a98') {
mceInit.toolbar1 = 'bold,italic,link';
}
}
return mceInit;
}
)
;
}
)(jQuery);
</script>
<?php
}
);