The is_favicon() WordPress PHP function checks if the current query is for the favicon.ico file.
Usage
To use the function, simply call it like this:
$is_favicon = is_favicon();
Parameters
There are no parameters for this function.
More information
See WordPress Developer Resources: is_favicon()
Examples
Display a message if favicon query
This example checks if the current query is for the favicon.ico file and displays a message if it is.
if (is_favicon()) { echo 'This is a favicon query.'; }
Redirect favicon query to a custom location
This example checks if the query is for the favicon.ico file and redirects it to a custom location.
if (is_favicon()) { wp_redirect('https://example.com/my-custom-favicon.ico'); exit; }
Add a custom header for favicon queries
This example adds a custom header to the favicon query response.
if (is_favicon()) { header('X-Custom-Header: Favicon-Request'); }
Log favicon requests
This example logs the favicon requests to a custom log file.
if (is_favicon()) { $logfile = fopen('favicon_requests.log', 'a'); fwrite($logfile, date('Y-m-d H:i:s') . ' - Favicon requested' . PHP_EOL); fclose($logfile); }
Serve a dynamic favicon
This example serves a dynamic favicon based on the current site’s theme color.
if (is_favicon()) { $theme_color = get_theme_mod('header_textcolor'); header('Content-Type: image/vnd.microsoft.icon'); echo create_dynamic_favicon($theme_color); exit; }