How to Get the Current Favicon in WordPress
Find the favicon your WordPress site uses now: where the Site Icon is stored, how to retrieve it in PHP or WP-CLI, how to confirm it, and what it means for your logo files.
Contents
- Where WordPress keeps the Site Icon
- Before you start
- Method 1: Check it in the dashboard
- Method 2: Retrieve it with PHP
- Method 3: Retrieve it with WP-CLI
- Method 4: Read it from the page source
- Confirm you have the right file
- What the retrieved file means for your logo artwork
- Dark mode and the single Site Icon
- Gaps to verify for your setup
WordPress calls the favicon the Site Icon. It stores the icon as an image attachment in the Media Library and saves that attachment's ID in the site_icon option. To get the current favicon in code, call get_site_icon_url(), which returns the icon's URL at a requested pixel size, or an empty string if no icon is set. Without code, open the Site Icon setting in the admin, or look for the link tags with rel="icon" in the page source.
The file you get back is a raster image. A raster image is a fixed grid of pixels, usually a PNG cropped to a square. It is not a vector image, which describes shapes as mathematical paths that scale to any size without losing quality. Retrieving the favicon gives you the delivered asset, not the logo's editable source artwork.
Where WordPress keeps the Site Icon
- Option: site_icon holds the attachment ID of the current icon. A value of 0 or no value means no icon is set.
- Attachment: the icon is a normal Media Library item. When you crop an image during setup, WordPress usually saves the crop as a separate attachment, and the original upload often remains in the library too.
- Output: on each page, the wp_site_icon() function prints the icon link tags into the document head at several generated sizes.
- Admin location: in classic themes, the setting is under Appearance, Customize, Site Identity. In block themes, it can be reached through the Site Logo block settings. Some recent versions also show it under Settings, General. Menu locations change between releases, so check them against the version you are running.
Before you start
- Admin access with permission to manage options, if you are using the dashboard.
- For the code methods: a child theme, a site-specific plugin, or WP-CLI access to the server. Do not edit a parent theme directly, because theme updates overwrite those changes.
- A note of any caching plugin, server cache or CDN in front of the site. Caches can show an outdated icon after you change it.
Method 1: Check it in the dashboard
- 1. Open the Site Icon setting for your theme type, using the locations listed above.
- 2. The preview there shows the image WordPress is currently set to use. If the setting is empty, no Site Icon is configured, and any favicon visitors see comes from somewhere else.
- 3. To find the file itself, go to Media, Library and look for the cropped icon. Its filename often starts with "cropped-". The attachment details panel shows the file URL and pixel dimensions.
Method 2: Retrieve it with PHP
Use these core functions in theme or plugin code. get_site_icon_url() takes three arguments: a size in pixels (default 512), a fallback URL, and a site ID for multisite networks. site_icon_url() prints the same value instead of returning it. has_site_icon() checks whether an icon exists.
<?php
if ( has_site_icon() ) {
// URL of the icon at roughly 512x512 pixels
$icon_url = get_site_icon_url( 512 );
// Smaller variant, e.g. for a browser-tab preview
$icon_32 = get_site_icon_url( 32 );
} else {
// No Site Icon set; supply your own fallback
$icon_url = get_site_icon_url( 512, get_stylesheet_directory_uri() . '/assets/fallback-icon.png' );
}
To work with the attachment itself, for example to read its dimensions or find the file on the server, start from the option value:
<?php
$icon_id = (int) get_option( 'site_icon' );
if ( $icon_id ) {
$full_url = wp_get_attachment_image_url( $icon_id, 'full' );
$file_path = get_attached_file( $icon_id ); // absolute server path
$meta = wp_get_attachment_metadata( $icon_id ); // width, height, generated sizes
}
On a multisite network, pass the site ID as the third argument, as in get_site_icon_url( 512, '', $blog_id ). Plugins and themes can change the returned value through the get_site_icon_url filter. If the result looks wrong, check whether something is hooked into that filter.
Method 3: Retrieve it with WP-CLI
If you have shell access, these commands return the attachment ID and the icon URL without changing any code:
wp option get site_icon
wp eval 'echo get_site_icon_url( 512 ) . PHP_EOL;'
Method 4: Read it from the page source
Open any front-end page, view the source, and search for rel="icon" and rel="apple-touch-icon". The Site Icon feature outputs several of these tags at different sizes. Their href values are the files browsers actually request. This is the most reliable way to find what visitors receive, because a theme or SEO plugin may print its own icon tags in addition to the core output or instead of it.
Confirm you have the right file
- Open the returned URL directly. It should load a square image, and its dimensions should match the size you requested or the nearest generated size.
- Compare it with the href values in the page source. If they point to different files, another theme or plugin is overriding the Site Icon, and the page source shows what visitors actually get.
- If you recently changed the icon, clear the site and CDN caches, then check in a private browser window. Browsers cache favicons aggressively, so a normal tab can keep showing the old icon after the files have changed.
- If get_site_icon_url() returns an empty string, has_site_icon() is false and no icon is configured. Set one before relying on any of the code above.
What the retrieved file means for your logo artwork
The Site Icon is a cropped, resampled pixel image. That makes it fine for confirming which mark is live, but a poor starting point for new artwork. Scaling it up blurs edges, and tracing it back to vector paths loses curve accuracy and any small type. For a new favicon, a dark-mode variant or any other logo deliverable, go back to the vector master file: usually an AI, EPS, PDF or SVG file from whoever made the logo. Keep in mind that a file extension does not prove the file contains editable vector paths. A PDF or SVG can just wrap an embedded bitmap, so open it and inspect the paths. Owning a copy of the icon also does not mean you have permission to reuse the logo elsewhere.
Dark mode and the single Site Icon
The core Site Icon setting holds one image. It has no separate field for a dark-mode version. To make a favicon adapt to dark browser themes, you can add your own SVG favicon link to the document head. Inside the SVG, a CSS prefers-color-scheme media query can switch fills between light and dark values. Keep the PNG Site Icon as the fallback for browsers and devices that do not use SVG favicons. Simplify the mark for this job: tiny sizes usually need solid shapes, no fine strokes, and no lettering. Test the result on both light and dark tab backgrounds. Support for SVG favicons and color-scheme switching varies by browser and version, so check behavior in the browsers your audience uses. The supplied material has no data on which browsers support this.
Gaps to verify for your setup
No version-specific evidence was supplied for this guide. Before you document a process for your team, confirm three things against your installed WordPress version and theme: where the Site Icon setting appears in the admin, the minimum upload size the dashboard recommends, and the exact set of icon sizes that wp_site_icon() generates.