Alchemy Options Docs
v1.0
v1.0
  • Read Me
  • Installation
  • Configuration
  • Meta Boxes
  • Samples
  • Field types
    • Text
    • Password
    • URL
    • Email
    • Tel
    • Textarea
    • Editor (WYSIWYG)
    • Datepicker
    • Image upload
    • Radio buttons
    • Select
    • Checkbox
    • Colorpicker
    • Image radio
    • Post type select
    • Datalist
    • Sections
    • Repeater
    • Button group
    • Slider
    • Taxonomy select
    • Field group
  • Functions
    • alch_options_id
    • alch_network_options_id
    • alch_get_option
    • alch_get_network_option
    • alch_delete_value
    • alch_get_post_meta
  • Javascript
    • getOption
    • getNetworkOption
    • getPostMeta
  • Filters
    • alch_options_id
    • alch_default_page_capabilities
    • alch_default_page_icon
    • alch_default_page_position
    • alch_network_options_id
    • alch_options_id() . '_args'
    • alch_network_options_id() . '_args'
    • alch_allowed_editor_html_tags
    • alch_allowed_editor_protocols
    • alch_{ $optionsPageID }_capabilities
    • alch_{ $optionsPageID }_icon
    • alch_{ $optionsPageID }_position
    • alch_value_{ $optionID }
    • alch_network_value_{ $optionID }
Powered by GitBook
On this page
  • Create an options page with 2 tabs
  • Simple text field
  • With a repeater field in one of two tabs
  • Network options

Samples

Add code to your theme's functions.php.

Create an options page with 2 tabs

function add_custom_options_pages( $pages ) {
    $myPages = array(
        array(
            'id' => 'my-options-page',
            'name' => 'My options page',
            'tabs' => array(
                array(
                    'id' => 'main',
                    'name' => 'Main',
                ),
                array(
                    'id' => 'inner',
                    'name' => 'Inner',
                ),
            ),
        ),
    );

    return array_merge( $pages, $myPages );
}

add_filter( 'alch_options_pages', 'add_custom_options_pages' );

Simple text field

The following will add a text field to the 'My options page'. If you don't specify a tab the field is going to render in each of them.

function add_custom_options( $options ) {
    $myOptions = array(
        array(
            'id' => 'text-option',
            'type' => 'text',
            'place' => array(
                'page' => 'my-options-page',
            ),
        ),
    );

    return array_merge( $options, $myOptions );
}

add_filter( 'alch_options', 'add_custom_options' );

To restrict the field to a particular tab use the tab key.

function add_custom_options( $options ) {
    $myOptions = array(
        array(
            'id' => 'text-option',
            'type' => 'text',
            'place' => array(
                'page' => 'my-options-page',
                'tab' => 'inner',
            ),
        ),
    );

    return array_merge( $options, $myOptions );
}

add_filter( 'alch_options', 'add_custom_options' );

With a repeater field in one of two tabs

function add_custom_repeaters( $repeaters ) {
	$myRepeaters = array(
		array(
			'id' => 'my-repeater',
			'fields' => array(
				array(
					'title' => 'My editor field',
					'id' => 'my-editor-field',
					'type' => 'editor',
				),
			),
		),
	);

	return array_merge( $repeaters, $myRepeaters );
}

add_filter( 'alch_repeaters', 'add_custom_repeaters' );


function add_custom_options( $options ) {
    $myOptions = array(
        array(
            'id' => 'text-option',
            'type' => 'text',
            'place' => array(
                'page' => 'my-options-page',
            ),
        ),
        array(
            'id' => 'repeater-option',
            'type' => 'repeater:my-repeater',
            'place' => array(
                'page' => 'my-options-page',
            ),
        ),
    );

    return array_merge( $options, $myOptions );
}

add_filter( 'alch_options', 'add_custom_options' );

Network options

The config is almost exactly the same as for regular options, only you should use the alch_network_options action instead of alch_options. E.g.

function add_custom_network_options( $options ) {
    $myOptions = array(
        array(
            'title' => 'My slider field title',
            'id' => 'slider-option',
            'desc' => 'Short description for the field',
            'place' => array(
                'page' => 'my-network-page',
                'tab' => 'tab-1'
            ),
            'type' => 'slider',
            'values' => array(
                'min' => 0,
                'max' => 200,
                'step' => 5,
            ),
        ),
    );

    return array_merge( $options, $myOptions );
}

add_action( 'alch_network_options', 'add_custom_network_options' );
PreviousMeta BoxesNextField types

Last updated 2 years ago