Theme Options Filters

The following filter is available to extend the theme options tabs:

tk_theme_options_fields

This filter is called to add each of the tabs on the theme options page. Tabs are added with different priorities to place them in order – General (4), Social Media (8), Sponsor/Partner logos (12), 404 page (16) and Admin (20).

Example

Adding a new tab to the theme options page with a text field and a WYSIWYG editor:

// this will place the tab between the General tab and Social Media tab
add_filter( 'tk_theme_options_fields', 'tk_theme_options_additional_tab', 6 );

// the function needs to return an array of ACF field definitions
function tk_theme_options_additional_tab( $options )
{
    $tab = apply_filters( 'tk_theme_options_additional_tab', array (
        array (
            'key' => 'field_tk_tab_additional_options',
            'label' => 'Additional Options',
            'type' => 'tab',
        ),          
        array (
            'key' => 'field_tk_tab_additional_options_title',
            'label' => 'Additonal title',
            'name' => 'tk_tab_additional_options_title',
            'type' => 'text',
            'placeholder' => 'Additional title',
        ),
        array (
            'key' => 'field_tk_tab_additional_options_content',
            'label' => 'Additional content',
            'name' => 'tk_tab_additional_options_content',
            'type' => 'wysiwyg',
            'tabs' => 'all',
            'toolbar' => 'basic',
            'media_upload' => 1,
        ),
    ) );
    return array_merge( $options, $tab );
}

This adds the new tab Additional Options to the theme options page, and places it between the General and Social Media Tabs.

In addition to adding new tabs, you can also use the following filters to extend existing tabs:

  • tk_theme_options_general_tab
    This filter is called on the contents of the General tab on the theme options page
  • tk_theme_options_social_media_tab
    This filter is called on the Social Media tab on the theme options page
  • tk_theme_options_sponsors_tab
    This filter is called on the Sponsor Logos tab on the theme options page
  • tk_theme_options_404_tab
    This filter is called on the 404 Page tab on the theme options page
  • tk_theme_options_admin_tab
    This filter is called on the Admin tab on the theme options page

Example

In the above example, the Additional Options tab fields were themselves sent through the tk_theme_options_additional_tab filter, in the same way that the default theme options tabs use the above filters. If you wanted to extend your Additional Options tab with some more fields, you could do the following:

// this will add fields to the additional options tab
add_filter( 'tk_theme_options_additional_tab', 'tk_theme_options_additional_tab_extras' );

// the function which adds fields to the additional options tab
function tk_theme_options_additional_tab_extras( $options )
{
    $extras = array(
        array (
            'key' => 'field_tk_tab_additional_options_include_subtitle',
            'label' => 'Include subtitle?',
            'name' => 'tk_tab_additional_options_include_subtitle',
            'type' => 'true_false',
            'ui' => 1,
        ),
        array (
            'key' => 'field_tk_tab_additional_options_subtitle',
            'label' => 'Additional subtitle',
            'name' => 'tk_tab_additional_options_subtitle',
            'type' => 'text',
            'conditional_logic' => array (
                array (
                    array (
                        'field' => 'field_tk_tab_additional_options_include_subtitle',
                        'operator' => '==',
                        'value' => 1,
                    ),
                ),
            ),
        ),
    );
    return array_merge( $options, $extras );
}

Adding these filters will result in a new tab on the theme options page which looks like this:

Post Settings

Post settings (Posts->Post Settings) are handled in a similar way to theme options, but in this case they use the tk_post_settings_fields filter to add tabs to the Post Settings page and the tk_post_settings_archive_tab and the tk_post_settings_single_tab filters for each tab on this page.

For more information about defining ACF fiels in PHP, please see the Register Fields via PHP page in the ACF documentation.