Halloween Sale 15% off Ends in See the plans
PHP

Default Block Editor Preferences for Everyone

Sets sensible defaults for every user of the block editor, such as the top toolbar, the List View opened and button text labels, while each person can still change them.

Don’t have WPIDE yet? Install it on your site

Code

// Editor preferences (true or false).
$wpide_editor_defaults = array(
    'fixedToolbar'          => true,
    'showListViewByDefault' => true,
    'showIconLabels'        => false,
    'showBlockBreadcrumbs'  => true,
);

add_action( 'enqueue_block_editor_assets', function () use ( $wpide_editor_defaults ) {
    wp_add_inline_script(
        'wp-preferences',
        'wp.domReady(function(){(window._wpLoadBlockEditor||Promise.resolve()).then(function(){wp.data.dispatch("core/preferences").setDefaults("core",' . wp_json_encode( array_map( 'boolval', $wpide_editor_defaults ) ) . ');});});'
    );
} );

Notes

Only defaults change; anything a user has already set in Preferences wins. Set a value to true or false to taste.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.