Alchemy Options Docs
v0.9
v0.9
  • Read Me
  • Installation
  • Configuration
  • Meta Boxes
  • Theme mode
  • 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_network_options_id
    • alch_options_id() . '_args'
    • alch_network_options_id() . '_args'
    • alch_allowed_editor_html_tags
    • alch_allowed_editor_protocols
    • alch_value_{ $optionID }
    • alch_network_value_{ $optionID }
Powered by GitBook
On this page
  • Simplest
  • With two tabs - Main and Inner
  • Network options
  • With a repeater field in one of two tabs

Samples

Add this code to your theme's functions.php.

Simplest

function add_custom_options() {
    if( ! class_exists( 'Alchemy_Options\Includes\Options' ) || wp_doing_ajax() ) {
        return;
    }

    $options = array(
        'options' => array(
            array(
                'id' => 'text-option',
                'type' => 'text',
            ),
        ),
    );

    new Alchemy_Options\Includes\Options( $options );
}

add_action( 'init', 'add_custom_options' );

With two tabs - Main and Inner

function add_custom_options() {
    if( ! class_exists( 'Alchemy_Options\Includes\Options' ) || wp_doing_ajax() ) {
        return;
    }

    $options = array(
        'tabs' => array(
            'main' => array(
                'title' => 'Main'
            ),
            'inner' => array(
                'title' => 'Inner'
            ),
        ),
        'options' => array(
            array(
                'title' => 'My text field title',
                'id' => 'text-option',
                'desc' => 'Short description for the field',
                'tab' => 'main',
                'type' => 'text',
            ),
        ),
    );

    new Alchemy_Options\Includes\Options( $options );
}

add_action( 'init', 'add_custom_options' );

Network options

The config is almost exactly the same, only you should use the Network_Options class instead of Options. E.g.

function add_custom_network_options() {
    if( ! class_exists( 'Alchemy_Options\Includes\Network_Options' ) || wp_doing_ajax() ) {
        return;
    }

    $options = array(
        'options' => array(
            array(
                'title' => 'My text field title',
                'id' => 'text-option',
                'desc' => 'Short description for the field',
                'type' => 'text',
            ),
        ),
    );

    new Alchemy_Options\Includes\Network_Options( $options );
}

add_action( 'init', 'add_custom_network_options' );

With a repeater field in one of two tabs

function add_custom_repeaters() {
    if( ! class_exists( 'Alchemy_Options\Includes\Repeaters' ) || wp_doing_ajax() ) {
        return;
    }

    $repeaters = array(
        array(
            'id' => 'my-repeater',
            'fields' => array(
                array(
                    'title' => 'My content title',
                    'desc' => 'Short description for the field',
                    'id' => 'content',
                    'type' => 'editor',
                ),
            ),
        ),
    );

    new Alchemy_Options\Includes\Repeaters( $repeaters );
}

add_action( 'init', 'add_custom_repeaters' );


function add_custom_options() {
    if( ! class_exists( 'Alchemy_Options\Includes\Options' ) || wp_doing_ajax() ) {
        return;
    }

    $options = array(
        'tabs' => array(
            'main' => array(
                'title' => 'Main'
            ),
            'inner' => array(
                'title' => 'Inner'
            ),
        ),
        'options' => array(
            array(
                'title' => 'My repeater field title',
                'id' => 'repeater-field',
                'desc' => 'Short description for the field',
                'type' => 'repeater:my-repeater',
                'tab' => 'inner',
            ),
        ),
    );

    new Alchemy_Options\Includes\Options( $options );
}

add_action( 'init', 'add_custom_options' );
PreviousTheme modeNextField types

Last updated 4 years ago