How to use multiple favicons for one site

。_饼干妹妹 提交于 2019-12-14 02:26:21

问题


I've done quite a bit of searching and reading on trying to find a solution but have not come up or across with anything that has worked for me just yet. I am building a site that carries a colored themed structure. I would like to have each page use a different colored favicon for it's corresponding page color. For example:

  • Page 1 / background color = blue -> blue favicon.
  • Page 2 / background color = red -> red favicon.
  • Etc.

The closest I came across was a using a PHP method and appending a number to the end of the icon file -

<?php echo '<link rel="shortcut icon" href="http://www.yoursite.com/favicon.ico?t=' . time() . '" />; ?>

Unless the php is wrong, this didn't seem to work for me. Im not the strongest in PHP but if anyone has any suggestions or relevant reading on this it would be appreciated.


回答1:


It's simpler than you think. No PHP required. Just change the URL to point to the path of the favicon you want.

On the blue favicon page:

<link rel="icon" href="http://www.yoursite.com/blue_favicon.ico" />

On the red favicon page:

<link rel="icon" href="http://www.yoursite.com/red_favicon.ico" />

Browsers, by default, look for /favicon.ico. But if you specify a different path and file it will use that instead.




回答2:


You can just make a simple if statement to help you decide which favicon you are going to display

<?php
       if ( condition to display first favicon )
           echo '<link rel="shortcut icon" href="http://www.yoursite.com/favicon1.ico" />';
       else
           echo '<link rel="shortcut icon" href="http://www.yoursite.com/favicon2.ico" />';
?>


来源:https://stackoverflow.com/questions/25005936/how-to-use-multiple-favicons-for-one-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!