官术网_书友最值得收藏!

  • WordPress 2.7 Cookbook
  • Jean-Baptiste Jung
  • 437字
  • 2021-04-01 13:55:49

Creating and integrating a favicon

A favicon is a small icon (16 x16 pixel) associated with a web site. The favicon is displayed by modern web browsers in the address bar, tabs, and bookmarks.

Nowadays, almost all the web sites and blogs have their own favicon. The following screenshot shows a favicon displayed in Mozilla Firefox:

Creating and integrating a favicon

Getting ready

You'll need a 16 x 16 pixels image to serve as a favicon. Due to the very small display size of the favicon, the image should be very simple.

Tip

I always tend to use a background color that fits my web site color scheme, and a simplified logo.

Basically, you can use .jpg, .png, .gif, or even .mng and .apng files to display a favicon. Unfortunately, the Internet Explorer (6 and 7) recognizes only the Windows .ico file format named favicon.ico.

Therefore, if you want to have an IE-compatible favicon, you'll have to convert your image file from png, gif, or jpg to Windows .ico.

Many imaging software applications can convert an image into a Windows icon file. Personally, I use an online service called ConvertIcon (available at the link http://converticon.com/) in order to convert my png image into Windows .ico file. The ConvertIcon application will also resize your image if needed. Therefore, there's no need to worry about your image width and height.

How to do it...

  1. Once you have your favicon ready, upload it on your server under the directory of your choice. Personally, I prefer putting it in wp-content/themes/mytheme/. However, the choice is yours.
  2. Open the header.php file from your theme. We now have to place a line of code to specify the location of our favicon. This line can be placed anywhere within the <head> and </head> tags.
  3. Here's the code that we shall use in order to define an Internet Explorer compliant favicon:
    <link rel="shortcut icon" type="image/x-icon" href="/path/to/your/favicon.ico" />

    The preceding line of code is the standard code to integrate a favicon on a web site. Using the .ico format, you can make sure that your favicon will be displayed by Internet Explorer, which doesn’t happen when using the .png version.

  4. If you uploaded your favicon into your wp-content/themes/yourtheme directory, we can use the bloginfo() function in order to automatically retrieve the template path as follows:
    <link rel="shortcut icon" type="image/x-icon" href="<?php bloginfo('template_url'); ?>/favicon.ico" />
  5. If you chose to use a file format, such as .gif, .png, or .jpg, you can add your favicon with the following code; however, Internet Explorer will not recognize it:
    <link rel="icon" type="image/png" href="favicon.png" />
  6. Once you have saved your header.php file, your favicon will be displayed.

How it works...

The following line of code is the standard code used to integrate a favicon on a web site:

<link rel="shortcut icon" type="image/x-icon" href="/path/to/your/favicon.ico" />
主站蜘蛛池模板: 出国| 锡林郭勒盟| 绥滨县| 托里县| 甘洛县| 翼城县| 永新县| 山东省| 临沭县| 万盛区| 汉源县| 大石桥市| 龙陵县| 共和县| 苍山县| 开封县| 江北区| 修武县| 屏南县| 连南| 博兴县| 府谷县| 龙州县| 政和县| 监利县| 安龙县| 巴青县| 志丹县| 潜山县| 新营市| 延寿县| 桃江县| 交城县| 静乐县| 镇康县| 南昌市| 柳林县| 张北县| 阳原县| 陆河县| 增城市|