Using WordPress ‘includes_url’ PHP filter

The includes_url WordPress PHP Filter allows you to modify the URL to the includes directory in WordPress.

Usage

function my_custom_includes_url($url, $path, $scheme) {
    // your custom code here
    return $url;
}
add_filter('includes_url', 'my_custom_includes_url', 10, 3);

Parameters

  • $url (string): The complete URL to the includes directory including scheme and path.
  • $path (string): Path relative to the URL to the wp-includes directory. Blank string if no path is specified.
  • $scheme (string|null): Scheme to give the includes URL context. Accepts ‘http’, ‘https’, ‘relative’, or null. Default null.

More information

See WordPress Developer Resources: includes_url

Examples

Change includes URL to use a CDN

Change the includes URL to use a content delivery network (CDN) for faster loading times.

function use_cdn_for_includes($url, $path, $scheme) {
    $cdn_url = 'https://cdn.example.com/wp-includes/';
    return $cdn_url . $path;
}
add_filter('includes_url', 'use_cdn_for_includes', 10, 3);

Force includes URL to use HTTPS

Make sure all includes URLs use HTTPS for better security.

function force_https_includes($url, $path, $scheme) {
    return set_url_scheme($url, 'https');
}
add_filter('includes_url', 'force_https_includes', 10, 3);

Use relative includes URL

Use relative URLs for the includes directory to avoid mixed content issues and improve compatibility.

function relative_includes_url($url, $path, $scheme) {
    return set_url_scheme($url, 'relative');
}
add_filter('includes_url', 'relative_includes_url', 10, 3);

Add a version parameter to includes URL

Add a version parameter to the includes URL to force browsers to load the latest version of a file.

function add_version_to_includes($url, $path, $scheme) {
    $version = '1.0.0';
    return add_query_arg('ver', $version, $url);
}
add_filter('includes_url', 'add_version_to_includes', 10, 3);

Remove query strings from includes URL

Remove query strings from the includes URL to improve caching and speed up the site.

function remove_query_strings_includes($url, $path, $scheme) {
    return remove_query_arg('ver', $url);
}
add_filter('includes_url', 'remove_query_strings_includes', 10, 3);