Img src tag keeps prepended number of folders

I was looking through the generated html of Kirby (2.4.1) and found that the img tag keeps the prepended number of content folders if I do not generate a thumb for the image.
This seems to be the only location in the html where the content folder is not stripped of the prepended visible number.

This will keep the prepended number in the html.

I’m sure I missed something to solve this issue. Currently, I can only correct this by creating a thumb for every image.

Any help would be greatly appreciated.

If you want to prevent using the prepended number, you can use a custom method:

file::$methods['permanentUrl'] = function($file) {
  $site = $file->site();
  return $site->url() . '/' .  $file->page()->id() . '/' . $file->filename();

(put this code into a file, e.g. methods.php, in /site/plugins)
If you have a multi language installation, you need to add the language code as well.

The you can use this method in your templates like this:

$image = $page->image('someimage.jpg');
if($image): ?>
  <img src="<?= $image->permanentUrl() ?> " alt="">
<?php endif ?>

Thank you for the quick reply. I already have something similar to this written as a work around.

I brought up this issue because it seems this solution might work best in the core code. I though since every other generated path already has the prepended number removed perhaps the image path should also have it removed.
Thanks again for the help.

I’ll check if there is already an issue on GitHub and if not, create one. This issue has come up before and there should at least be an option.

1 Like

You can upvote this here: