Skip to content

Instantly share code, notes, and snippets.

@bkozma
Last active September 25, 2023 09:30
Show Gist options
  • Save bkozma/e7483b65c27664bf848ca4f540fea1b7 to your computer and use it in GitHub Desktop.
Save bkozma/e7483b65c27664bf848ca4f540fea1b7 to your computer and use it in GitHub Desktop.
ACF WYSIWYG Editor Customization example
<?php
//ACF Editor customization
function mindset_toolbars( $toolbars )
{
// Uncomment to view format of $toolbars
/*
echo '< pre >';
print_r($toolbars);
echo '< /pre >';
die;
*/
// Add a NEW toolbar called "Extremely Basic"
// - this toolbar has only 1 row of buttons
$toolbars['Extremely Basic' ] = array();
$toolbars['Extremely Basic' ][1] = array('bold' , 'italic' , 'underline' );
// Add a NEW toolbar called "Mindset Custom"
// - this toolbar has only 1 row of buttons
$toolbars['Mindset Custom' ] = array();
$toolbars['Mindset Custom' ][1] = array('pastetext' ,'bold' , 'italic' , 'underline', 'formatselect', 'blockquote', 'link', 'unlink', 'removeformat' );
// Edit the "Full" toolbar, and remove 'underline' from the 2nd row
if( ($key = array_search('underline' , $toolbars['Full' ][2])) !== false )
{
unset( $toolbars['Full' ][2][$key] );
}
// Edit the "Full" toolbar and remove 'alignleft' from the 1st row
if( ($key = array_search('alignleft' , $toolbars['Full' ][1])) !== false )
{
unset( $toolbars['Full' ][1][$key] );
}
// Edit the "Full" toolbar and add 'fontsizeselect' if not already present.
if (($key = array_search('fontsizeselect' , $toolbars['Full'][2])) !== true) {
array_unshift($toolbars['Full'][2], 'fontsizeselect');
}
// remove the 'Basic' toolbar completely
unset( $toolbars['Basic' ] );
// return $toolbars - IMPORTANT!
return $toolbars;
}
add_filter( 'acf/fields/wysiwyg/toolbars' , 'mindset_toolbars' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment