Weird behaviour with kirbytags

I’d like my users to use kirbytags inside the text block, as they find it way quicker than using the image or video block. I need to customize how the (image: ) and (video: ) tags are rendered.

Let’s say I created a couple of custom kirbytag:

  • (myimage: )
  • (myyoutube: ).

The weird thing is that all the images and videos using my custom kirbytags are rendered at the top of the page, regardless where they compare in the text block. Same images and videos, using standard tags, are displayed correctly.

To be clearer:

This is how the block appears from the backend: both images are below the “Lorem ipsum” text.

…and this is how it appears on the front end: the image which uses the custom kirbytag is displayed above the text:

Of course… both have the same html markup! :frowning:

Why???

Could you post the code of your custom tag?

Sure. Here it is:

function tag_custom_image($tag) 
  {
      $imgurl     = $tag->parent()->file($tag->value)->url();
      $alt        = $tag->attr('alt');
      $caption    = $tag->attr('caption');
  
      $altTxt = $alt > '' ? $alt : $caption;
      echo $img = '<figure class="small"><img alt="' . $altTxt . '" src="' . $imgurl . '"></figure>';
  }

Ok, that’s what I thought. It happens because you echo instead of returning your HTML.

Correct! Thank you @texnixe!