Make Favicon Editable in the Kirby Panel

Hello, Hello i have a Question i have a Favicon Markup

<link rel="shortcut icon" href="assets/favicon.png" >

and i would like to make the favicon editable in the Kirby Panel, can i do id whit <?php echo $site->favicon()->kirbytext() ?> or something like that?. Hope you can Help me :slight_smile:


You can create an image field in your site.yml blueprint, let’s call it favicon:

  type: image
  label: favicon

Then in your code use:

<link rel="shortcut icon" href="<?= $site->image($site->favicon())->url() ?>" >

Note: there is no check to see if the favicon exists in the code I shared. You may want to add that. See @lukasbestle’s post below if you want to find out how: Make Favicon Editable in the Kirby Panel

Thats the error Message that i god Parse error: syntax error, unexpected '" > ' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' in C:\xampp\htdocs\ceevee\site\templates\default.php on line 24

and this is my Blueprint Example

      label: Favicon
      type: image

and so looks it in the Editor

the default.css have a another color, like the other one’s, maybe there is a problem whit the default.css?

Yes, basically, but the CSS file itself is not the issue. What you see there is strange syntax highlighting because the PHP code wasn’t closed:

<link rel="shortcut icon" href="<?= $site->image($site->favicon())->url() ?>">

If you compare the <link color of the shortcut icon with the ones of the CSS files, you see that they are different as well. That helps finding the issue.

Now i have Just a whit site. and i can see any changes in the site Blueprint

Here’s The Full Example

title: Site
files: true
pages: false
    label: Title
    type:  text
      label: Copyright
      type:  text
      icon: copyright
      label: Favicon
      type: image

The blueprint is fine. But have you actually selected an image for the favicon in the Panel?

BTW: You should probably use this code, however that shouldn’t change anything with the white page issue:

<link rel="icon" href="<?= $site->image($site->favicon())->url() ?>" type="image/png">

i have upload the favicon.png File

…and have you selected it in the Panel?

i’m so… i was in The wrong site :sweat:. now it works Correctly, but if i dont select a favicon, the site is white

Yep, that’s what @Thiousi wrote above. The code doesn’t check if the file actually exists.
You can use the following code to do that:

<?php if($favicon = $site->favicon()->toFile()): ?>
  <link rel="icon" href="<?= $favicon->url() ?>" type="image/png">
<?php endif ?>

Okay, Thanks a lot @lukasbestle and @Thiousi

I forgot to close the tag sorry…
I updated my original post.