# Configuration

Make sure you have Alchemy Options [installed](https://docs.alchemy-options.com/installation).

## Creating option pages

To create an Alchemy Options option page use the `alch_options_pages` hook:

```php
function add_custom_options_pages( $pages ) {
    $myPages = array(
        array(
            'id' => 'my-options-page',
            'name' => 'My options page',
        )
    );

    return array_merge( $pages, $myPages );
}

add_filter( 'alch_options_pages', 'add_custom_options_pages' );
```

This will add an options page to the WordPress sidebar.

![](https://2294767099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKMTiOPVR7pXWhebz7q%2Fsync%2Ffc4e70176b33da235704e74600ebcc11812987c6.png?generation=1618345549664501\&alt=media)

By default, top-level pages are added after the Appearance section, but you can filter the page [position](https://docs.alchemy-options.com/filters/alch_default_page_position), as well as its [capabilities](https://docs.alchemy-options.com/filters/alch_default_page_capabilities) and [icon](https://docs.alchemy-options.com/filters/alch_default_page_icon) via respective hooks.

## Creating option pages with subpages

An Alchemy Options option page can have subpages, you can specify them in the `subpages` array like so:

```php
function add_custom_options_pages( $pages ) {
    $myPages = array(
        array(
            'id' => 'my-options-page',
            'name' => 'My options page',
            'subpages' => array(
                array(
                    'id' => 'my-options-subpage',
                    'name' => 'My options subpage',
                ),
            ),
        )
    );

    return array_merge( $pages, $myPages );
}

add_filter( 'alch_options_pages', 'add_custom_options_pages' );
```

This adds an options page with a subpage to the WordPress sidebar.

![](https://2294767099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKMTiOPVR7pXWhebz7q%2Fsync%2F30d1ff536a186aa51151f4dc372e199b9e0ac2df.png?generation=1618345549609028\&alt=media)

By default, the top-level page gets duplicated as a subpage producing 2 identical page titles. You can modify them like so:

```php
function add_custom_options_pages( $pages ) {
    $myPages = array(
        array(
            'id' => 'my-options-page',
            'name' => 'My options page',
            'subpages' => array(
                array(
                    'id' => 'my-options-page',
                    'name' => 'General',
                ),
                array(
                    'id' => 'my-options-subpage',
                    'name' => 'My options subpage',
                ),
            ),
        )
    );

    return array_merge( $pages, $myPages );
}

add_filter( 'alch_options_pages', 'add_custom_options_pages' );
```

This will produce nicer page names without title duplication.

![](https://2294767099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKMTiOPVR7pXWhebz7q%2Fsync%2F2293aee7677f5d22fb61abb50071f4de18e74b6d.png?generation=1618345549864459\&alt=media)

Notice that in order for it to work the top-level and subpage `id`s should be the same.

## Adding options to option pages

To add options to Alchemy Options option pages use the `alch_options` hook:

```php
function add_custom_options( $options ) {
    $myOptions = array(
        /* options will go here */
    );

    return array_merge( $options, $myOptions );
}

add_filter( 'alch_options', 'add_custom_options' );
```

That's it, just add [some options](https://docs.alchemy-options.com/fields) instead of `/* options will go here */` and see them appear on the page.

## Grouping

If there's a need to split options into several groups, Alchemy Options has got you covered. You may add the `tabs` section to the config that looks like this:

```php
...
'tabs' => array(
    array(
        'id' => 'tab-1',
        'name' => 'Name'
    ),
    array(
        'id' => 'tab-2',
        'name' => 'Name 2'
    ),
)
...
```

IDs of the tabs should be unique, these values will be used in configuring of each option with the `tab` key. If no `tab` key is found in the option's settings it will be rendered in each tab.

If there's a need to split options even further, there's a [`sections`](https://docs.alchemy-options.com/fields/sections) type for visual splitting of fields into togglable sections and a [`field-group`](https://docs.alchemy-options.com/fields/field-group) type to group related fields together for an easier [value retrieval](https://docs.alchemy-options.com/functions/alch_get_option).
