Support

Account

Home Forums ACF PRO Add style select to custom toolbar Reply To: Add style select to custom toolbar

  • 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;
    }