Skip to content
Radoslav Georgiev edited this page Oct 21, 2018 · 2 revisions

Purpose

Tabs allow you to group the fields in your container and only show the fields, which belong to the current tab.

tabs

Adding tabs

In the interface, tabs are treated like any other field. Just select "Tab" as the field type and adjust the tabs' settings. In PHP the behavior is similar. You have to create a new field of the tab type and add it to the standard flow.

All fields, added after the tab will be assigned to it, until a new tab is found.

$container->add_fields(array(
	Field::create( 'tab', 'first_tab' ),
	Field::create( 'text', 'first_tab_field' ),
	Field::create( 'tab', 'seconc_tab' ),
	Field::create( 'text', 'second_tab_field' ),
));

Settings

Icon

You can use the Dashicons icon font in order to add icons to tabs.

In PHP you need to use the set_icon method of the tab and provide it with the CSS class of the icon.

Field::create( 'tab', 'appearance' )
	->set_icon( 'dashicons-art' )

Conditional Logic

Tabs, as well as any other field, support conditional logic.

When a tab has conditional rules added to it, those rules affect not only the tab, but also the fields, contained within that tab. When there are no valid matches for the logic behind a tab, it will be grayed-out (disabled) and will not be clickable. The fields within a tab will also not be validated if the tab is not active.

Clone this wiki locally