Using WordPress ‘is_favicon()’ PHP function

The is_favicon() WordPress PHP function checks if the current query is for the favicon.ico file.


To use the function, simply call it like this:

$is_favicon = is_favicon();


There are no parameters for this function.

More information

See WordPress Developer Resources: is_favicon()


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()) {

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);

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/');
    echo create_dynamic_favicon($theme_color);