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

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" />
主站蜘蛛池模板: 福海县| 江安县| 临夏市| 兴业县| 黔西县| 石景山区| 阿鲁科尔沁旗| 四川省| 潍坊市| 安新县| 沙河市| 饶平县| 定兴县| 梁山县| 巫山县| 邯郸市| 盐边县| 三穗县| 乾安县| 两当县| 射阳县| 高密市| 衡阳市| 蓬安县| 大石桥市| 宜丰县| 分宜县| 兰州市| 秭归县| 景洪市| 黄骅市| 治多县| 克拉玛依市| 高州市| 平南县| 高陵县| 靖州| 屏东市| 柞水县| 宁国市| 灯塔市|