Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Forked from courtneymyers/acf_modifications.php
Created November 15, 2018 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbrocks/f2735c380571a7a037466f85ce7d1362 to your computer and use it in GitHub Desktop.
Save pbrocks/f2735c380571a7a037466f85ce7d1362 to your computer and use it in GitHub Desktop.
Reduces initial height of Advanced Custom Fields WYSIWYG fields to 100px, and enables autoresizing of WYSIWYG field, as text is entered. Best practice would be to include this function in a site-specific plugin.
<?php
/*
* -----------------------------------------------------------------------------
* Advanced Custom Fields Modifications
* -----------------------------------------------------------------------------
*/
function PREFIX_apply_acf_modifications() {
?>
<style>
.acf-editor-wrap iframe {
min-height: 0;
}
</style>
<script>
(function($) {
// (filter called before the tinyMCE instance is created)
acf.add_filter('wysiwyg_tinymce_settings', function(mceInit, id, $field) {
// enable autoresizing of the WYSIWYG editor
mceInit.wp_autoresize_on = true;
return mceInit;
});
// (action called when a WYSIWYG tinymce element has been initialized)
acf.add_action('wysiwyg_tinymce_init', function(ed, id, mceInit, $field) {
// reduce tinymce's min-height settings
ed.settings.autoresize_min_height = 100;
// reduce iframe's 'height' style to match tinymce settings
$('.acf-editor-wrap iframe').css('height', '100px');
});
})(jQuery)
</script>
<?php
}
/*
* -----------------------------------------------------------------------------
* WordPress hooks
* -----------------------------------------------------------------------------
*/
add_action('acf/input/admin_footer', 'PREFIX_apply_acf_modifications');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment