PHP - Add 'meta' tag to all pages loading the script, and this script is outside 'head' tag

StackOverflow https://stackoverflow.com/questions/22412452

  •  14-06-2023
  •  | 
  •  

Question

I need to add a meta tag to all files of a website, so I thought about adding that meta tag by PHP code, within header.php, menu.php or footer.php; something like:

<?php addToHeadTag("Meta: favicon='./img/favicon.ico'"); ?>

It has a lot of files and manually changing each file is out of hand.

P.S.: All possible files in which I could include that code are outside head.

Was it helpful?

Solution

First of all, you can place an include file wherever you like in your code. Though that really has nothing to do with the problem at hand.

You should not be using header() for this. header() provides the client browser with meta information on the http response as a whole.

Take a look at this link for usage information on favicons:

http://en.wikipedia.org/wiki/Favicon

In most cases you can just place the favicon.ico in your web root and the browser will pick it up automatically without any markup at all. You can also use a <link> element.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top