PHPackages                             arcath/theme-options - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. arcath/theme-options

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arcath/theme-options
====================

Class for defining theme options and retrieving them.

0.0.3(3y ago)0124MITPHPPHP &gt;5.3.3

Since Mar 24Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Arcath/theme-options)[ Packagist](https://packagist.org/packages/arcath/theme-options)[ RSS](/packages/arcath-theme-options/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

Theme Options
=============

[](#theme-options)

Theme Options Made Easy

Install
=======

[](#install)

Either install from composer `arcath/theme-options` or place `theme-options.php` in your theme and require it.

Usage
=====

[](#usage)

Create a new ThemeOptions instance

```
$themeOptions = new Arcath\ThemeOptions('slug');
```

In the `init` action define all your fields e.g.

```
function slug_custom_fields(){
  global $themeOptions;

  $themeOptions->addThemeOptionCustomControl('logo_light',
    array(
      'type' => 'option',
      'default' => 0
    ),
    array(
      'section' => 'images',
      'label' => __('Light Logo', 'slug'),
      'description' => __('Light Logo used on darker backgrounds', 'glug'),
    ),
    'WP_Customize_Image_Control'
  );

  $themeOptions->addThemeOption('email',
    array(
      'capability' => 'edit_theme_options',
      'type'       => 'option',
      'default'    => 'foo@bar.com',
    ),
    array(
      'label' => 'Email',
      'section' => 'text',
      'description' => __('Your Email')
    )
  );
}

add_action('init', 'slug_custom_fields');
```

In `customize_register` create your sections/panels and apply the theme options.

```
function slug_apply_custom_fields($wp_customize){
  global $themeOptions;

  $wp_customize->add_panel('global', array(
    'priority' => 1,
    'capability'     => 'edit_theme_options',
    'theme_supports' => '',
    'title'          => __('Global Options', 'slug'),
    'description'    => __('Global options that affect every page.', 'edit2017'),
  ));

  $wp_customize->add_section(
    'images',
    array(
      'title' => 'Images',
      'description' => 'Images used throughout the Theme',
      'capability' => 'edit_theme_options',
      'panel' => 'global'
    )
  );

  $wp_customize->add_section(
    'text',
    array(
      'title' => 'Text',
      'description' => 'Text Fields',
      'capability' => 'edit_theme_options',
      'panel' => 'global'
    )
  );
}

add_action('customize_register', 'slug_apply_custom_fields');
```

Then in your Theme you can pull any option using:

```
