Size

The Size controller allows users to enter or modify a size with an appropriate size unit.

Demonstration

 
Handy::control( 'size', [
    'id'          => 'size_id',
    'section'     => 'layout_section',
    'label'       => esc_html__( 'Size Control', 'textdomain' ),
    'description' => esc_html__( 'Description Here', 'textdomain' ),
    'placeholder' => esc_html__( 'Enter Size', 'textdomain' ),
    'priority'    => 1
]);

TIP

Here's an example using the default parameter. Note the default value's size unit must exist in defined units.

 
Handy::control( 'size', [
    'id'          => 'size_id',
    'section'     => 'layout_section',
    'default'     => '100px',
    'label'       => esc_html__( 'Size Control', 'textdomain' ),
    'description' => esc_html__( 'Description Here', 'textdomain' ),
    'placeholder' => esc_html__( 'Enter Size', 'textdomain' ),
    'priority'    => 1
]);

TIP

Here's an example using the units parameter. These are the list of allowed size units. px, %, pt, pc, in, q, mm, cm, em, ex, ch, rem, lh, rlh, vw, vh, vmin, vmax, vb, vi, swv, svh, lvw, lvh, dvw and dvh.

 
Handy::control( 'size', [
    'id'          => 'size_id',
    'section'     => 'layout_section',
    'default'     => '100px',
    'label'       => esc_html__( 'Size Control', 'textdomain' ),
    'description' => esc_html__( 'Description Here', 'textdomain' ),
    'placeholder' => esc_html__( 'Enter Size', 'textdomain' ),
    'priority'    => 1,
    'units'       => [ '%', 'px', 'em', 'rem' ]
]);

Basic Usage

 
// Return a string.
$value = get_theme_mod( 'size_id' );

Parameters

NameDescription
id

string required

The unique slug like string used as an ID and also as an index name in storing data in a database.

section

string required

The ID of the section in which the control will be displayed.

default

string optional

The predetermined value of the control. The default value's size unit must exist in defined units. Default empty.

units

array optional

The size's supported unit size. Accepts only px, %, pt, pc, in, q, mm, cm, em, ex, ch, rem, lh, rlh, vw, vh, vmin, vmax, vb, vi, swv, svh, lvw, lvh, dvw and dvh. Default empty array.

label

string optional

The label or title of the control to show in the UI. Default empty.

description

string optional

The description of the control to show in the UI. Default empty.

placeholder

string optional

The placeholder of the control to show in the UI. Default empty.

priority

integer optional

The order of control appears in the section. Default 0.

validations

array optional

The set of validations used to validate the value of the control. For further details, read validations. Default empty.

active_callback

callable optional

A callback function that determines the visibility of a control, whether to show or hide depending on a condition. For further details, read active_callback. Default empty.

sanitize_callback

callable optional

A callback function that sanitizes the value of control before storing it in the database. Note that this is only optional since each control is already well sanitized. For further details, read sanitize_callback. Default empty.