The get_site_icon_url WordPress PHP filter modifies the site icon URL.
Usage
add_filter('get_site_icon_url', 'your_custom_function', 10, 3); function your_custom_function($url, $size, $blog_id) { // your custom code here return $url; }
Parameters
$url
(string) – Site icon URL.$size
(int) – Size of the site icon.$blog_id
(int) – ID of the blog to get the site icon for.
More information
See WordPress Developer Resources: get_site_icon_url
Examples
Change site icon URL based on the blog ID
This example changes the site icon URL based on the $blog_id
.
add_filter('get_site_icon_url', 'change_site_icon_url_based_on_blog_id', 10, 3); function change_site_icon_url_based_on_blog_id($url, $size, $blog_id) { if ($blog_id == 2) { $url = 'https://example.com/custom_icon_2.png'; } elseif ($blog_id == 3) { $url = 'https://example.com/custom_icon_3.png'; } return $url; }
Add a custom site icon for a specific size
This example sets a custom site icon for a specific size.
add_filter('get_site_icon_url', 'add_custom_site_icon_for_specific_size', 10, 3); function add_custom_site_icon_for_specific_size($url, $size, $blog_id) { if ($size == 64) { $url = 'https://example.com/custom_icon_64.png'; } return $url; }
Add a custom site icon with a dynamic size
This example sets a custom site icon with a dynamic size in the URL.
add_filter('get_site_icon_url', 'add_custom_site_icon_with_dynamic_size', 10, 3); function add_custom_site_icon_with_dynamic_size($url, $size, $blog_id) { $url = 'https://example.com/custom_icon_' . $size . '.png'; return $url; }
Replace the site icon URL with a CDN URL
This example replaces the site icon URL with a CDN URL.
add_filter('get_site_icon_url', 'replace_site_icon_url_with_cdn', 10, 3); function replace_site_icon_url_with_cdn($url, $size, $blog_id) { $url = str_replace('https://example.com', 'https://cdn.example.com', $url); return $url; }
Add a query string to the site icon URL
This example adds a query string to the site icon URL for cache busting.
add_filter('get_site_icon_url', 'add_query_string_to_site_icon_url', 10, 3); function add_query_string_to_site_icon_url($url, $size, $blog_id) { $url = add_query_arg('version', '1.0', $url); return $url; }