Using WordPress ‘customize_value_{$this->id_data[‘base’]}’ PHP filter

The customize_value_{$this->id_data[‘base’]} WordPress PHP filter allows you to modify a Customize setting value that is not handled as a theme_mod or option.

Usage

add_filter('customize_value_my_setting', 'my_custom_function', 10, 1);

function my_custom_function($default) {
    // Your custom code here

    return $default;
}

Parameters

  • $default (mixed): The setting default value. Default empty.

More information

See WordPress Developer Resources: customize_value_{$this->id_data[‘base’]}

Examples

Change the default value of a custom setting

Modify the default value of a custom setting called ‘my_custom_setting’.

add_filter('customize_value_my_custom_setting', 'change_my_custom_setting_default', 10, 1);

function change_my_custom_setting_default($default) {
    $default = 'new_default_value';
    return $default;
}

Append a text to a custom setting value

Add a copyright notice to a custom footer text setting called ‘footer_text’.

add_filter('customize_value_footer_text', 'append_copyright_to_footer_text', 10, 1);

function append_copyright_to_footer_text($default) {
    $default .= ' © ' . date('Y') . ' My Website';
    return $default;
}

Modify a custom setting value based on user role

Change the value of ‘welcome_message’ based on the user role.

add_filter('customize_value_welcome_message', 'modify_welcome_message_for_role', 10, 1);

function modify_welcome_message_for_role($default) {
    if (current_user_can('manage_options')) {
        $default = 'Welcome, admin!';
    } else {
        $default = 'Welcome, user!';
    }
    return $default;
}

Add a prefix to a custom setting value

Add a prefix to a custom setting called ‘page_title’.

add_filter('customize_value_page_title', 'add_prefix_to_page_title', 10, 1);

function add_prefix_to_page_title($default) {
    $default = 'My Website - ' . $default;
    return $default;
}

Make a custom setting value uppercase

Transform a custom setting value called ‘header_text’ to uppercase.

add_filter('customize_value_header_text', 'make_header_text_uppercase', 10, 1);

function make_header_text_uppercase($default) {
    $default = strtoupper($default);
    return $default;
}