Check if Favicon is set in Customizer

There's this "Site Icon" option in the customizer, which allows you to set a favicon. I'm creating a theme which already has its own favicon.

How can I check if the favicon is already set in the customizer?

Topic theme-customizer favicon php Wordpress

Category Web


WordPress saves the Favicon as site_icon in the options table holding the attachment post ID. What you could do is something like this:

if( false === get_option( 'site_icon', false ) ) {
    // Show favicon
}

Where get_option() will hit the default ( we provide as the 2nd parameter ) false IF the site_icon does not exist or one has not been uploaded through the customizer.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.