WordPress 4.3 introduces the site icon function, allowing users to define a representative icon for the website, which is the website favicon we are familiar with. This article will dive into site icons and their APIs, including their capabilities and filters.
What is the site icon?
If you are familiar with web development, you may already know what the site icon is. It is what WordPress calls favicon. Favicon is an icon that appears on the browser tab when a website is opened, and it is also an icon that appears when you save a web shortcut on your smartphone home screen. After setting up the site icon, it will also appear in your WordPress admin panel.
WordPress 4.3 enables site icon display by default, no additional actions are required. You can use this feature directly as long as you update WordPress to version 4.3.
How to define site icons?
You can define site icons through the theme customizer. There are two ways to access:
- From the Admin menu, find the Custom option under the Appearance menu.
- Click the "Custom" button in the admin bar (New in WordPress 4.3).
In the Site Identification option in the Theme Customizer, you can upload or select an image as a site icon. WordPress recommends image sizes of at least 512 pixels wide and high.
After selecting the image, you can crop the image and select the square area you want to be the site icon. Cropping does not modify the original file.
After cropping is completed, click the "Crop Image" button, and WordPress will automatically resize the image. Click the "Save and Publish" button to save the changes.
You can remove or change site icons at any time using the theme customizer.
Get the current site icon
Theme or plugin developers don't need to worry about the basic usage of site icons: After selecting an image, WordPress will automatically display it as favicon.
But if you need to get the current site icon in a theme or plugin, you can use four functions provided by WordPress:
-
has_site_icon()
: Check if the site icon is set, returning a boolean value (true or false).
if (has_site_icon()) { // 已设置站点图标 } else { // 未设置站点图标 }
-
get_site_icon_url()
andsite_icon_url()
: Get the site icon URL.get_site_icon_url()
You can specify the blog ID and size, andsite_icon_url()
directly output the URL.
if (has_site_icon()) { echo '<img alt="Site Icon" src="' . get_site_icon_url(null, 200) . '">'; }
-
wp_site_icon()
: Output the necessary meta tags to inform the browser or operating system of the available sizes of favicon.
wp_site_icon(); // 通常放在 `<head>` 标签内
Custom site icon size
WordPress generates several sizes of site icons by default. You can use the site_icon_image_sizes
and site_icon_meta_tags
to customize the size and meta tags.
Summary
WordPress site icon API has simple and practical functions, making it convenient for users and developers to manage website favicon. Remember, this API is mainly used for favicon and is not used for other purposes.
(FAQs part is omitted because it is highly duplicated with existing content and is longer.)
The above is the detailed content of All You Need to Know About the New WordPress Site Icon API. For more information, please follow other related articles on the PHP Chinese website!

Have you seen the "Error establishing a database connection" error page on your WordPress website? There are several reasons for displaying this message, but it is unattractive and may confuse visitors. Additionally, you won’t realize that your website is closed until you visit the website and see the message. In this article, we will show you how to customize database error pages in WordPress. We will also show you how to set notifications every time your website is closed due to a database error. What is the reason for an error in establishing a database connection? "Error establishing a database connection" is one of the most common WordPress errors.

Did your WordPress post return a 404 error on the site? This error occurs when you have access to WordPress admin areas and blogs, but when you try to open a post, you will see "404 Not Found". In this article, we will show you how to fix WordPress posts that return 404 errors. What causes WordPress posts to return a 404 error? WordPress is a powerful content management system (CMS), but minor changes can sometimes lead to your WordPress

In 2025, choosing the perfect WordPress theme is no longer a priority. The real challenge is choosing a topic that is flexible enough to meet the needs of the current project and adapt to the evolution of future needs. The good news is that you don't have to start from scratch. Whether you are building a website for your customers or expanding your own digital products, the following topics strike the ideal balance between design freedom, technical performance, and long-term reliability. These topics are built by developers who understand the important factors: regular updates, clean code, mobile-first responsive design, and compatibility with tools you already use, such as Elementor, Gutenberg, and WooCommerce. In this review, we have narrowed the scope to 9

Blogs are the ideal platform for people to express their opinions, opinions and opinions online. Many newbies are eager to build their own website but are hesitant to worry about technical barriers or cost issues. However, as the platform continues to evolve to meet the capabilities and needs of beginners, it is now starting to become easier than ever. This article will guide you step by step how to build a WordPress blog, from theme selection to using plugins to improve security and performance, helping you create your own website easily. Choose a blog topic and direction Before purchasing a domain name or registering a host, it is best to identify the topics you plan to cover. Personal websites can revolve around travel, cooking, product reviews, music or any hobby that sparks your interests. Focusing on areas you are truly interested in can encourage continuous writing

Can learn WordPress within three days. 1. Master basic knowledge, such as themes, plug-ins, etc. 2. Understand the core functions, including installation and working principles. 3. Learn basic and advanced usage through examples. 4. Understand debugging techniques and performance optimization suggestions.

WordPress is a Content Management System (CMS). It provides content management, user management, themes and plug-in capabilities to support the creation and management of website content. Its working principle includes database management, template systems and plug-in architecture, suitable for a variety of needs from blogs to corporate websites.

WordPressisgoodforvirtuallyanywebprojectduetoitsversatilityasaCMS.Itexcelsin:1)user-friendliness,allowingeasywebsitesetup;2)flexibilityandcustomizationwithnumerousthemesandplugins;3)SEOoptimization;and4)strongcommunitysupport,thoughusersmustmanageper

Wix is suitable for users who have no programming experience, and WordPress is suitable for users who want more control and expansion capabilities. 1) Wix provides drag-and-drop editors and rich templates, making it easy to quickly build a website. 2) As an open source CMS, WordPress has a huge community and plug-in ecosystem, supporting in-depth customization and expansion.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool