Skip to content

Typography Field

A comprehensive typography control with Google Fonts integration and live preview.

Overview

The Typography field renders a full typography control panel — font family selection with a searchable Google Fonts browser (1,899 fonts), font weight, font size, line height, letter spacing, text transform, and font style. It returns an associative array of typography values. Use it for body text, headings, navigation, buttons, or any other typographic element in your theme.

Field Registration

[
    'id'       => 'body_typography',
    'type'     => 'typography',
    'title'    => __( 'Body Typography', 'your-textdomain' ),
    'subtitle' => __( 'Font settings for the main body text', 'your-textdomain' ),
    // Control toggles — only font-family and subsets are enabled by default.
    // Explicitly enable each control you want to show in the UI:
    'font-size'      => true,
    'font-weight'    => true,
    'font-style'     => true,
    'line-height'    => true,
    'letter-spacing' => true,
    'text-transform' => true,
    'subsets'        => true,
    'default' => [
        'font-family'    => 'Inter',
        'font-weight'    => '400',
        'font-size'      => '16',
        'line-height'    => '1.6',
        'letter-spacing' => '0',
        'text-transform' => 'none',
        'font-style'     => 'normal',
        'subsets'        => ['latin'],
    ],
]

Field Options

OptionTypeRequiredDescription
idstringUnique field identifier — used as the option key
typestringMust be typography
titlestringLabel shown above the field
subtitlestringSmaller descriptive text shown below the label
descstringHelp text shown below the typography controls
defaultarrayDefault typography values — see default keys below
requiredarrayConditional logic rules — see Conditional Logic

Control Toggles

By default only font-family and subsets are enabled. Every other control must be explicitly turned on:

ToggleTypeDefaultDescription
font-familybooltrueFont family selector with Google Fonts browser
subsetsbooltrueGoogle Fonts subset selector
font-sizeboolfalseFont size input
font-weightboolfalseFont weight selector
font-styleboolfalseFont style (normal / italic)
line-heightboolfalseLine height input
letter-spacingboolfalseLetter spacing input
text-transformboolfalseText transform selector

To show only the font family picker (minimum config):

[
    'id'    => 'nav_font',
    'type'  => 'typography',
    'title' => __( 'Navigation Font', 'your-textdomain' ),
]

To enable every control:

[
    'id'             => 'body_typography',
    'type'           => 'typography',
    'title'          => __( 'Body Typography', 'your-textdomain' ),
    'font-size'      => true,
    'font-weight'    => true,
    'font-style'     => true,
    'line-height'    => true,
    'letter-spacing' => true,
    'text-transform' => true,
    'subsets'        => true,
]

Return Value

Type: array

Returns an associative array of typography values, or the default array if nothing has been saved yet.

$typography = themeplus_get_option( 'body_typography', [] );
// Returns:
// [
//     'font-family'    => 'Inter',
//     'font-weight'    => '400',
//     'font-size'      => '16',
//     'line-height'    => '1.6',
//     'letter-spacing' => '0',
//     'text-transform' => 'none',
//     'font-style'     => 'normal',
//     'subsets'         => ['latin'],
// ]

Return Value Keys

KeyTypeDescription
font-familystringFont name — e.g. 'Inter''Roboto'
font-weightstringFont weight — e.g. '400''700'
font-sizestringFont size in px, no unit — e.g. '16'
line-heightstringLine height — e.g. '1.6'
letter-spacingstringLetter spacing in px, no unit — e.g. '0''1'
text-transformstringText transform — 'none''uppercase''lowercase''capitalize'
font-stylestringFont style — 'normal' or 'italic'
subsetsarrayGoogle Fonts subsets — e.g. ['latin']['latin', 'latin-ext']

Usage Examples

Generating CSS custom properties

$body = themeplus_get_option( 'body_typography', [] );

if ( ! empty( $body ) ) {
    echo '<style>
        body {
            font-family:     "' . esc_attr( $body['font-family'] ?? 'inherit' ) . '", sans-serif;
            font-weight:     ' . esc_attr( $body['font-weight'] ?? '400' ) . ';
            font-size:       ' . absint( $body['font-size'] ?? 16 ) . 'px;
            line-height:     ' . esc_attr( $body['line-height'] ?? '1.6' ) . ';
            letter-spacing:  ' . esc_attr( $body['letter-spacing'] ?? '0' ) . 'px;
            text-transform:  ' . esc_attr( $body['text-transform'] ?? 'none' ) . ';
            font-style:      ' . esc_attr( $body['font-style'] ?? 'normal' ) . ';
        }
    </style>';
}

Multiple typography fields as CSS custom properties

$options = themeplus_get_option();

$body     = $options['body_typography']    ?? [];
$heading  = $options['heading_typography'] ?? [];
$nav      = $options['nav_typography']     ?? [];

echo '<style>:root{';

if ( ! empty( $body['font-family'] ) ) {
    echo '--font-body: "' . esc_attr( $body['font-family'] ) . '", sans-serif;';
    echo '--font-size-base: ' . absint( $body['font-size'] ?? 16 ) . 'px;';
    echo '--line-height-base: ' . esc_attr( $body['line-height'] ?? '1.6' ) . ';';
}

if ( ! empty( $heading['font-family'] ) ) {
    echo '--font-heading: "' . esc_attr( $heading['font-family'] ) . '", serif;';
    echo '--font-weight-heading: ' . esc_attr( $heading['font-weight'] ?? '700' ) . ';';
}

if ( ! empty( $nav['font-family'] ) ) {
    echo '--font-nav: "' . esc_attr( $nav['font-family'] ) . '", sans-serif;';
}

echo '}</style>';

Heading typography

[
    'id'      => 'heading_typography',
    'type'    => 'typography',
    'title'   => __('Heading Typography', 'your-textdomain'),
    'subtitle' => __('Applied to all H1–H6 headings', 'your-textdomain'),
    'default' => [
        'font-family'    => 'Poppins',
        'font-weight'    => '700',
        'font-size'      => '36',
        'line-height'    => '1.2',
        'letter-spacing' => '0',
        'text-transform' => 'none',
        'font-style'     => 'normal',
    ],
]

With a conditional field

[
    'id'      => 'enable_custom_fonts',
    'type'    => 'toggle',
    'title'   => __('Enable Custom Fonts', 'your-textdomain'),
    'default' => false,
],
[
    'id'       => 'body_typography',
    'type'     => 'typography',
    'title'    => __('Body Font', 'your-textdomain'),
    'required' => ['enable_custom_fonts', '==', true],
],
[
    'id'       => 'heading_typography',
    'type'     => 'typography',
    'title'    => __('Heading Font', 'your-textdomain'),
    'required' => ['enable_custom_fonts', '==', true],
],

Google Fonts

When a Google Font is selected, ThemePlus automatically enqueues it on the frontend using the Google Fonts API. You do not need to manually enqueue the font — just use the font-family value in your CSS.

Custom fonts uploaded via the Custom Fonts module also appear in the font family selector alongside Google Fonts.

Notes

  • Only font-family and subsets controls are enabled by default. Add 'font-size' => true'font-weight' => true, etc. to the field config to show additional controls.
  • Only enabled controls appear in the saved value — if font-size is not enabled, font-size will not be present in the returned array. Always use ?? fallbacks.
  • font-size and letter-spacing are returned as numeric strings without a unit — append 'px' when using in CSS.
  • The subsets key returns an array (e.g. ['latin', 'latin-ext']) — ThemePlus uses it for Google Fonts enqueueing. You do not need to use it in your CSS output.
  • Google Fonts are automatically enqueued on the frontend when a Google Font is selected — no manual enqueue needed.

On This Page