Tighter, Bolder Headings Through theme.json
Sets the weight, line height and letter spacing of all headings in a block theme, for a crisper, more modern look in the editor and on the site.
Opens WPIDE on
Code
// Heading typography.
$wpide_heading_weight = '700';
$wpide_heading_line_height = '1.15';
$wpide_heading_letter_spacing = '-0.02em';
add_filter( 'wp_theme_json_data_theme', function ( $theme_json ) use ( $wpide_heading_weight, $wpide_heading_line_height, $wpide_heading_letter_spacing ) {
return $theme_json->update_with( array(
'version' => WP_Theme_JSON::LATEST_SCHEMA,
'styles' => array(
'elements' => array(
'heading' => array(
'typography' => array(
'fontWeight' => $wpide_heading_weight,
'lineHeight' => $wpide_heading_line_height,
'letterSpacing' => $wpide_heading_letter_spacing,
),
),
),
),
) );
} );
Notes
Adjust the three values at the top. Individual blocks can still override them.
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.