admin管理员组文章数量:1130349
I am looking for help to put single page favicon that would overwrite global one. Say for example I have wordpress website that is example and it has favicon set for every page. What I want is for example/page3 to have diffrent favicon. I have seen quite a few options around but I cannot figure out how to make it work (my coding skills are limited). This solution:
<?php
echo '<link rel="shortcut icon" href=".ico?t=' . time() . '" />';
?>
Is marked as working one, but I cannot figure out how to set it up. Thank you for help
I am looking for help to put single page favicon that would overwrite global one. Say for example I have wordpress website that is example and it has favicon set for every page. What I want is for example/page3 to have diffrent favicon. I have seen quite a few options around but I cannot figure out how to make it work (my coding skills are limited). This solution:
<?php
echo '<link rel="shortcut icon" href="http://www.yoursite/favicon.ico?t=' . time() . '" />';
?>
Is marked as working one, but I cannot figure out how to set it up. Thank you for help
Share Improve this question asked Nov 1, 2018 at 9:45 Perovic Perovic 11 bronze badge 2- You can add a new header for page3 and have different favicon rel link for that. – thehbhatt Commented Nov 1, 2018 at 10:32
- Thank you for answer but how can I do that? Page have header built with Elementor page builder. – Perovic Commented Nov 1, 2018 at 11:42
2 Answers
Reset to default 2If you have a modern theme, where you can upload a favicon with the theme customizer (rather than a hardcoded url in the header.php), you can simply use a filter. Take a look at the function get_site_icon. As you can see it returns the url of the image that you have uploaded using the customizer. However, before it does so, it runs it through a filter, allowing you to change it under any condition you would like. For instance, to change it when you are on a page with ID=3:
add_filter( 'get_site_icon_url','wpse318165_filter_favicon', 10, 3 );
function wpse318165_filter_favicon ($url, $size, $blog_id) {
global $post;
if ( is_page( 3 ) ) $url = 'path-to-other-favicon';
return $url;
}
Here is the link: https://elementor/blog/header-footer-builder/
there is a video link on this page which explains how can you create/use multiple header with Elementor plugin.
Normally if you have FTP access go to theme folder and duplicate header.php and name it something relevant ie. header-blog.php
Then you can call that file in your page/templates via <?php get_header('blog); ?>
In your new header file use the rel link you've got for custom favicon. That's it :)
I am looking for help to put single page favicon that would overwrite global one. Say for example I have wordpress website that is example and it has favicon set for every page. What I want is for example/page3 to have diffrent favicon. I have seen quite a few options around but I cannot figure out how to make it work (my coding skills are limited). This solution:
<?php
echo '<link rel="shortcut icon" href=".ico?t=' . time() . '" />';
?>
Is marked as working one, but I cannot figure out how to set it up. Thank you for help
I am looking for help to put single page favicon that would overwrite global one. Say for example I have wordpress website that is example and it has favicon set for every page. What I want is for example/page3 to have diffrent favicon. I have seen quite a few options around but I cannot figure out how to make it work (my coding skills are limited). This solution:
<?php
echo '<link rel="shortcut icon" href="http://www.yoursite/favicon.ico?t=' . time() . '" />';
?>
Is marked as working one, but I cannot figure out how to set it up. Thank you for help
Share Improve this question asked Nov 1, 2018 at 9:45 Perovic Perovic 11 bronze badge 2- You can add a new header for page3 and have different favicon rel link for that. – thehbhatt Commented Nov 1, 2018 at 10:32
- Thank you for answer but how can I do that? Page have header built with Elementor page builder. – Perovic Commented Nov 1, 2018 at 11:42
2 Answers
Reset to default 2If you have a modern theme, where you can upload a favicon with the theme customizer (rather than a hardcoded url in the header.php), you can simply use a filter. Take a look at the function get_site_icon. As you can see it returns the url of the image that you have uploaded using the customizer. However, before it does so, it runs it through a filter, allowing you to change it under any condition you would like. For instance, to change it when you are on a page with ID=3:
add_filter( 'get_site_icon_url','wpse318165_filter_favicon', 10, 3 );
function wpse318165_filter_favicon ($url, $size, $blog_id) {
global $post;
if ( is_page( 3 ) ) $url = 'path-to-other-favicon';
return $url;
}
Here is the link: https://elementor/blog/header-footer-builder/
there is a video link on this page which explains how can you create/use multiple header with Elementor plugin.
Normally if you have FTP access go to theme folder and duplicate header.php and name it something relevant ie. header-blog.php
Then you can call that file in your page/templates via <?php get_header('blog); ?>
In your new header file use the rel link you've got for custom favicon. That's it :)
本文标签: phpChangable favicon
版权声明:本文标题:php - Changable favicon 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749210698a2333309.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论