Halloween Sale 15% off Ends in See the plans
PHP

"Larger Text in the Editor" Profile Option

Adds a checkbox to each user's profile that makes the text in the block editor larger and more spaced out, for authors who find the default editor text hard to read.

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

Code

add_action( 'personal_options', function ( $user ) {
    printf(
        '<tr><th scope="row">Editor text</th><td><label><input type="checkbox" name="wpide_editor_large" value="1" %s> Show larger text in the block editor</label></td></tr>',
        checked( get_user_meta( $user->ID, 'wpide_editor_large', true ), '1', false )
    );
} );

$wpide_save_editor_pref = function ( $user_id ) {
    if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'update-user_' . $user_id ) ) {
        update_user_meta( $user_id, 'wpide_editor_large', empty( $_POST['wpide_editor_large'] ) ? '0' : '1' );
    }
};
add_action( 'personal_options_update', $wpide_save_editor_pref );
add_action( 'edit_user_profile_update', $wpide_save_editor_pref );

add_filter( 'block_editor_settings_all', function ( $settings ) {
    if ( '1' === get_user_meta( get_current_user_id(), 'wpide_editor_large', true ) ) {
        $settings['styles'][] = array( 'css' => 'body{font-size:22px!important;line-height:1.7!important;}p,li{letter-spacing:.01em;}' );
    }

    return $settings;
}, 20 );

Notes

Only changes how content looks while editing; the published page is not affected.

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.