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!

WordPressisuser-friendlyduetoitsintuitiveinterfaceandCMS,whichseparatescontentfromdesign.Itoffersarichtexteditorforeasycontentcreationandamedialibraryfororganization.Itsflexibilityisenhancedbynumerousthemesandplugins,thoughoverusecanimpactperformance

WordPressissuitableforbusinesssettings.1)Itsupportse-commercewithpluginslikeWooCommerce,allowingproductmanagementandpaymentprocessing.2)ItservesasaCMSforcorporateblogs,enhancingSEOandengagement.3)Customizationispossiblewithnumerousthemesandplugins.4)

WordPressisnotidealforhigh-trafficwebsites,customandcomplexapplications,security-sensitiveapplications,real-timedataprocessing,andhighlycustomizeduserinterfaces.Forhigh-trafficsites,useNext.jsorcustomsolutions;forcomplexapplications,optforDjangoorRub

Yes,youcanbuildablogwithWordPress.1)ChoosebetweenWordPress.comforbeginnersorWordPress.orgformorecontrol.2)Selectathemetopersonalizeyourblog'slook.3)Usepluginstoenhancefunctionality,likeSEOandsocialmediaintegration.4)Customizeyourthemewithsimplecodetw

WordPresscanbesecureifmanagedproperly.1)KeeptheWordPresscoreupdatedtopatchvulnerabilities.2)Vetandupdatepluginsandthemesfromreputablesources.3)Enforcestrongpasswordsandusetwo-factorauthentication.4)Chooseahostingproviderwithgoodsecuritypractices.5)Ed

WordPresscanbuildvarioustypesofwebsites:1)Personalblogs,easytosetupwiththemesandplugins.2)Businesswebsites,usingdrag-and-dropbuilders.3)E-commerceplatforms,withWooCommerceforseamlessintegration.4)Communitysites,usingBuddyPressorbbPress.5)Educationalp

WordPressisapowerfulCMSwithsignificantadvantagesandchallenges.1)It'suser-friendlyandcustomizable,idealforbeginners.2)Itsflexibilitycanleadtositebloatandsecurityissuesifnotmanagedproperly.3)Regularupdatesandperformanceoptimizationsarenecessarytomainta

WordPressexcelsineaseofuseandadaptability,makingitidealforbeginnersandsmalltomedium-sizedbusinesses.1)EaseofUse:WordPressisuser-friendly.2)Security:Drupalleadswithstrongsecurityfeatures.3)Performance:GhostoffersexcellentperformanceduetoNode.js.4)Scal


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

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.
