I’ve created a new toolbar as decribed in this support article: https://www.advancedcustomfields.com/resources/customize-the-wysiwyg-toolbars/ and assigned it to a custom field.
I don’t need any buttons in the toolbar, just a custom style select but I can’t figure out the syntax to insert it.
I’ve used the support article at http://stackoverflow.com/questions/32441471/add-custom-style-button-to-wysiwyg-in-advanced-custom-fields to create a custom style select which appears in the main WYSIWYG toolbar, but I don’t want it to appear in the custom toolbar. I need a separate custom style select to appear in the custom toolbar.
Any help would be much appreciated.
It’s a year later but thought I’d post a solution – was trying to combine the wrong methods, and it’s actually a lot simpler than I’d thought. The issue was knowing how to insert the style select, but I didn’t how it was referred to in ACF arrays.
1) Find out the names of the toolbar elements for reference later on. In functions.php add the following:
add_filter( 'acf/fields/wysiwyg/toolbars' , 'my_toolbars' );
function my_toolbars( $toolbars )
{
echo '< pre >';
print_r($toolbars);
echo '< /pre >';
die;
}
2) Look at the bottom of the WP admin area and copy the array into a text file for future reference. We now know the names of the buttons.
< pre >Array
(
[Full] => Array
(
[1] => Array
(
[0] => formatselect
[1] => bold
[2] => italic
[3] => bullist
[4] => numlist
[5] => blockquote
[6] => alignleft
[7] => aligncenter
[8] => alignright
[9] => link
[10] => unlink
[12] => spellchecker
[14] => wp_adv
)
[2] => Array
(
[0] => styleselect
[1] => strikethrough
[2] => hr
[4] => removeformat
[5] => charmap
[6] => outdent
[7] => indent
[8] => undo
[9] => redo
)
[3] => Array
(
)
[4] => Array
(
)
)
[Basic] => Array
(
[1] => Array
(
[0] => bold
[1] => italic
[2] => underline
[3] => blockquote
[4] => strikethrough
[5] => bullist
[6] => numlist
[7] => alignleft
[8] => aligncenter
[9] => alignright
[10] => undo
[11] => redo
[12] => link
[13] => unlink
[14] => fullscreen
)
)
)
< /pre >
3) Remove or comment out the code above that displays the button array. Create your new custom toolbar.
add_filter( 'acf/fields/wysiwyg/toolbars' , 'custom_toolbars' );
function custom_toolbars( $toolbars )
{
// Add a new toolbar called "Custom" - only 1 row of buttons
$toolbars['Custom' ] = array();
$toolbars['Custom' ][1] = array('styleselect','bold','italic');
// return $toolbars
return $toolbars;
}
You must be logged in to reply to this topic.
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 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.