Create Editable Website Favicon

I want the ability to change the website’s favicon in the panel but nothing is showing up. I tried referencing this topic: Make Favicon Editable in the Kirby Panel but nothing seems to be working.

This is my site blueprint:
title: Site

columns:
  left:
    width: 1/2
    sections:
      content:
        type: fields
        fields:
          description:
            label: Description
            type: textarea
            buttons: false
          keywords:
            label: Keywords
            type: textarea
            buttons: false
  right:
    width: 1/2
    sections:
      favicon:
        type: files
        template: default
        layout: list
        multiple: false
      pages:
        type: pages

And this is what is in my template:

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

Well, you are using a files section, but that only gives you the option to upload a file, not to select it. You can now do one of two things.

Either, you use another template for the file, e.g. template: favicon. Then you can fetch the image in your template by this template.

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

You would have to change your section, because it doesn’t have a multiple option, what you need is max: 1 instead.

Or, you would have to add an additional files field, where the user can then select the file. Then pick the file from that field. I’d use the solution outlined above in this case.

I created the template: favicon and now have this in my blueprint:

sections:
      favicon:
        type: files
        template: favicon
        layout: list
        max: 1

and added this to my template:

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

Now I am getting an error that says “Function name must be a string.”

try <?= $favicon->url() ?> instead.

2 Likes

That did it bvdputte!

Thank you both for your help!