The customize_load_themes WordPress PHP filter allows you to modify theme data that’s loaded in the customizer. You can load theme data from an external source or modify data loaded from wp_prepare_themes_for_js()
or WordPress.org via themes_api()
.
Usage
add_filter('customize_load_themes', 'my_customize_load_themes', 10, 3); function my_customize_load_themes($themes, $args, $manager) { // your custom code here return $themes; }
Parameters
$themes
(array|stdClass): Nested array or object of theme data.$args
(array): List of arguments, such as page, search term, and tags to query for.$manager
(WP_Customize_Manager): Instance of the Customize manager.
More information
See WordPress Developer Resources: customize_load_themes
Examples
Add a custom theme to the theme list
Add a custom theme from an external source to the theme list in the customizer.
add_filter('customize_load_themes', 'add_custom_theme', 10, 3); function add_custom_theme($themes, $args, $manager) { $custom_theme = array( 'name' => 'My Custom Theme', 'screenshot' => 'https://example.com/my-custom-theme/screenshot.jpg' // add more theme properties here ); array_push($themes, $custom_theme); return $themes; }
Remove themes with a specific tag
Remove themes from the customizer that have a specific tag.
add_filter('customize_load_themes', 'remove_themes_by_tag', 10, 3); function remove_themes_by_tag($themes, $args, $manager) { $filtered_themes = array(); foreach ($themes as $theme) { if (!in_array('specific-tag', $theme['tags'])) { $filtered_themes[] = $theme; } } return $filtered_themes; }
Modify the theme data
Change the theme name for all themes in the customizer.
add_filter('customize_load_themes', 'modify_theme_names', 10, 3); function modify_theme_names($themes, $args, $manager) { foreach ($themes as &$theme) { $theme['name'] = 'New Name: ' . $theme['name']; } return $themes; }
Sort themes by name
Sort themes in the customizer by their name.
add_filter('customize_load_themes', 'sort_themes_by_name', 10, 3); function sort_themes_by_name($themes, $args, $manager) { usort($themes, function ($a, $b) { return strcmp($a['name'], $b['name']); }); return $themes; }
Filter themes by a specific author
Display only themes created by a specific author in the customizer.
add_filter('customize_load_themes', 'filter_themes_by_author', 10, 3); function filter_themes_by_author($themes, $args, $manager) { $filtered_themes = array(); foreach ($themes as $theme) { if ($theme['author'] == 'John Doe') { $filtered_themes[] = $theme; } } return $filtered_themes; }