php - Changable favicon

admin2025-06-06  0

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
Add a comment  | 

2 Answers 2

Reset to default 2

If 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 :)

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749210730a317288.html

最新回复(0)