search
HomeCMS TutorialWordPressAll You Need to Know About the New WordPress Site Icon API

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

All You Need to Know About the New WordPress Site Icon API

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.

All You Need to Know About the New WordPress Site Icon API

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.

All You Need to Know About the New WordPress Site Icon API

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.

All You Need to Know About the New WordPress Site Icon API

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() and site_icon_url(): Get the site icon URL. get_site_icon_url() You can specify the blog ID and size, and site_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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How easy is it to manage content with WordPress?How easy is it to manage content with WordPress?May 09, 2025 am 12:11 AM

WordPressisuser-friendlyduetoitsintuitiveinterfaceandCMS,whichseparatescontentfromdesign.Itoffersarichtexteditorforeasycontentcreationandamedialibraryfororganization.Itsflexibilityisenhancedbynumerousthemesandplugins,thoughoverusecanimpactperformance

How is WordPress used in business settings?How is WordPress used in business settings?May 08, 2025 am 12:04 AM

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

What types of websites are not a good fit for WordPress?What types of websites are not a good fit for WordPress?May 07, 2025 am 12:10 AM

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

Can you build a blog with WordPress?Can you build a blog with WordPress?May 06, 2025 am 12:03 AM

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

How secure is WordPress as a CMS platform?How secure is WordPress as a CMS platform?May 05, 2025 am 12:01 AM

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

What kind of websites can you build with WordPress CMS?What kind of websites can you build with WordPress CMS?May 04, 2025 am 12:06 AM

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

What are the pros and cons of using WordPress as your CMS?What are the pros and cons of using WordPress as your CMS?May 03, 2025 am 12:09 AM

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

How does WordPress compare to other popular CMS platforms?How does WordPress compare to other popular CMS platforms?May 02, 2025 am 12:18 AM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Safe Exam Browser

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

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

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

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows

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.