Support

Account

Home Forums General Issues How to edit the ACF WYSIWYG block format options?

Solving

How to edit the ACF WYSIWYG block format options?

  • Hi hope this is straight forward. I want to be able to edit the dropdown menu in the WYSIWYG editor to only provide paragraph and title. The title should be h4. I can universally do it to all editors globally with this:

    add_filter('tiny_mce_before_init', 'tiny_mce_remove_unused_formats' );
    
    function tiny_mce_remove_unused_formats($init) {
    	// Add block format elements you want to show in dropdown
    	$init['block_formats'] = 'Paragraph=p;Heading=h4';
    	return $init;
    }

    but I don’t really want that as I want to leave default WordPress post / page editor in tact with all options available.

    I can also edit other aspects of an instance of an ACF WYSIWYG like this as previously presented here on the ACF support forum:

    add_filter( 'acf/fields/wysiwyg/toolbars' , 'my_toolbars'  );
    function my_toolbars( $toolbars )
    {
    
        $toolbars['Very Simple' ] = array();
        $toolbars['Very Simple' ][1] = array('bold' , 'italic' , 'underline', 'strikethrough', 'formatselect' );
    
        return $toolbars;
    }
    
    add_filter('tiny_mce_before_init', 'tiny_mce_remove_unused_formats' );

    but that only modifies all other aspects of the WYSIWYG.

    So how do I merge both those scripts to just edit one instance of an ACF WYSIWYG?

    Thanks

  • Wow, this was posted some time ago. I am also looking for something very similar.

  • You can use JS for this.

    Here is how you can add JS:
    https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/

    And there is a JS filter for changing settings of tinymce (wysiwyg editor) before it’s initialized.
    https://www.advancedcustomfields.com/resources/javascript-api/#filters-wysiwyg_tinymce_settings

    And here is the final code. Just change ‘field_abcd123456’ to whatever is the key of your field.

    
    add_action('acf/input/admin_footer', function(){
        ?>
        <script>
    
            acf.addFilter('wysiwyg_tinymce_settings', function( mceInit, id, field ){
                if(field.get('key') !== 'field_abcd123456'){
                    return mceInit;
                }
                mceInit.block_formats = 'Paragraph=p;Heading 4=h4';
                return mceInit;
            });
    
        </script>
        <?php
    });
    
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.