Set the Body Text Size and Line Height
Sets the default font size and line height of body text in a block theme through theme.json, for more comfortable reading on every page.
Opens WPIDE on
Code
// Body text settings.
$wpide_body_font_size = 'clamp(1rem, 0.95rem + 0.25vw, 1.125rem)';
$wpide_body_line_height = '1.65';
add_filter( 'wp_theme_json_data_theme', function ( $theme_json ) use ( $wpide_body_font_size, $wpide_body_line_height ) {
return $theme_json->update_with( array(
'version' => WP_Theme_JSON::LATEST_SCHEMA,
'styles' => array(
'typography' => array(
'fontSize' => $wpide_body_font_size,
'lineHeight' => $wpide_body_line_height,
),
),
) );
} );
Notes
A clamp() size scales between phones and desktops; use a fixed value like 18px if you prefer.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.