Using WordPress ‘icon_dirs’ PHP filter

The icon_dirs WordPress PHP Filter allows you to modify the array of icon directory URIs.

Usage

add_filter('icon_dirs', 'your_function_name');
function your_function_name($uris) {
    // your custom code here
    return $uris;
}

Parameters

  • $uris (string[]): Array of icon directory URIs keyed by directory absolute path.

More information

See WordPress Developer Resources: icon_dirs

Examples

Add a custom icon directory

Add a new icon directory URI to the existing array.

add_filter('icon_dirs', 'add_custom_icon_directory');
function add_custom_icon_directory($uris) {
    // Add a new icon directory
    $uris['/path/to/custom/icons'] = '/uri/to/custom/icons';
    return $uris;
}

Remove an icon directory

Remove an existing icon directory URI from the array.

add_filter('icon_dirs', 'remove_icon_directory');
function remove_icon_directory($uris) {
    // Remove an icon directory
    unset($uris['/path/to/icons/to/remove']);
    return $uris;
}

Replace an icon directory

Replace an existing icon directory URI with a new one.

add_filter('icon_dirs', 'replace_icon_directory');
function replace_icon_directory($uris) {
    // Replace an icon directory
    $uris['/path/to/old/icons'] = '/uri/to/new/icons';
    return $uris;
}

Modify icon directory URI

Modify the URI of an existing icon directory.

add_filter('icon_dirs', 'modify_icon_directory_uri');
function modify_icon_directory_uri($uris) {
    // Modify the icon directory URI
    $uris['/path/to/icons'] = '/new/uri/to/icons';
    return $uris;
}

Filter icon directories by a condition

Filter the icon directories based on a specific condition.

add_filter('icon_dirs', 'filter_icon_directories');
function filter_icon_directories($uris) {
    // Filter out icon directories based on a condition
    $filtered_uris = array_filter($uris, function ($uri) {
        return strpos($uri, 'example') === false;
    });

    return $filtered_uris;
}