# Embedding Snippets

**URL:** <https://forum.getkirby.com/t/embedding-snippets/900>\
**Category:** Questions\
**Tags:** v2\
**Created:** [April 25, 2015, 3:30pm UTC](https://forum.getkirby.com/t/embedding-snippets/900 "2015-04-25T15:30:41Z")\
**Posts on this page:** 17\
**Page:** 2

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [December 7, 2017, 10:32pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/22 "2017-12-07T22:32:28Z")

</div>

Yes. Imageshrink and Focus

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 7, 2017, 10:39pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/23 "2017-12-07T22:39:48Z")

</div>

Does it make any difference if you remove those plugins? Can’t see how those would interfere, though.

Edit: I just saw something else: the original snippet you posted, is not wrapped in a container, but should be. Could you try that, please?

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [December 7, 2017, 10:56pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/24 "2017-12-07T22:56:56Z")

</div>

Good eye. I wrapped my snippet code in a DIV and it worked. I wouldn’t have thought of that. I’ll have to chalk that up as a rule to remember.

Thanks for your help!!!

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 8, 2017, 8:19am UTC](https://forum.getkirby.com/t/embedding-snippets/900/25 "2017-12-08T08:19:55Z")

</div>

FYI: The HTML in a Kirbytag definition has to be wrapped in a container as well.

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [March 26, 2019, 8:50pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/26 "2019-03-26T20:50:41Z")

</div>

Does this snippet tag need to be revised to work in Kirby v3?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 26, 2019, 8:54pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/27 "2019-03-26T20:54:01Z")

</div>

The snippet itself: no; the way you create your custom kirbytag: yes.

`/site/plugins/custom-tags/index.php`

```auto
<?php
Kirby::plugin('yourname/custom-tags', [

    'tags' => [
        'snippet' => [
            'html' => function($tag) {
                return snippet('snippetname');
            }
        ]
    ]
]);

```

Or with dynamic snippet names

```auto
<?php
Kirby::plugin('yourname/custom-tags', [

    'tags' => [
        'snippet' => [
            'html' => function($tag) {
                $snippetName = $tag->value();
                return snippet($snippetName);
            }
        ]
    ]
]);

```

---

<div class="post-metadata">

**Author:** ![pjs](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/pjs/32/6484_2.png) [@pjs](https://forum.getkirby.com/u/pjs)\
**Post date:** [April 9, 2019, 7:32pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/28 "2019-04-09T19:32:40Z")

</div>

@texnixe Is there something further that one needs to do to make the V3 plug-in above (dynamic snipped names) besides install it to the plug-in folder? Despite installation (plugins\>custom-tags\>custom-tags.php), my snippet tags are not replaced.

Example:

Version: (snippet: version-snippet)

… where version-snippet.php is in the snippets folder.

Even after installing the plug-in, this is rendered on the live HTML page as:

Version: (snippet: version-snippet)

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [April 9, 2019, 7:36pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/29 "2019-04-09T19:36:01Z")

</div>

There was a typo, now corrected, if you just copied it as is, maybe that is the issue.

---

<div class="post-metadata">

**Author:** ![pjs](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/pjs/32/6484_2.png) [@pjs](https://forum.getkirby.com/u/pjs)\
**Post date:** [April 9, 2019, 7:40pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/30 "2019-04-09T19:40:30Z")

</div>

Got it. I fixed the typo, but same results on the issue I’m seeing.

Even if I simply:

`return "hello";`

… “(snippet: version-snippet)” still appears in my rendered text. It’s as if the plug-in isn’t recognized at all.

---

<div class="post-metadata">

**Author:** ![pjs](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/pjs/32/6484_2.png) [@pjs](https://forum.getkirby.com/u/pjs)\
**Post date:** [April 9, 2019, 7:41pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/31 "2019-04-09T19:41:39Z")

</div>

Sorry, I’m a dummy. I was naming the plugin “custom-tags.php” instead of “index.php”. All fixed. Thanks. 🙂

---

<div class="post-metadata">

**Author:** ![pjs](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/pjs/32/6484_2.png) [@pjs](https://forum.getkirby.com/u/pjs)\
**Post date:** [April 9, 2019, 7:47pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/32 "2019-04-09T19:47:44Z")

</div>

Actually, I now have a follow-up issue. The snippet text always renders at the top of my page.

This is my Markdown file:

_Text:_  
_test1_  
_(snippet: version-snippet)_  
_test2_

Yet, when visiting the rendered page, it appears as:

_1.0_  
_test1_

_test2_

(“1.0” is the content of the snippet)

Any idea on why it’d always render at the top of the page vs. inline where it’s supposed to go?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [April 9, 2019, 8:04pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/33 "2019-04-09T20:04:30Z")

</div>

```auto
 return snippet($snippetName, [], true);

```

---

<div class="post-metadata">

**Author:** ![Chimara2501](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@Chimara2501](https://forum.getkirby.com/u/Chimara2501)\
**Post date:** [January 8, 2021, 2:59pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/34 "2021-01-08T14:59:42Z")

</div>

Thank you for this great help! I would like to reopen this post: everything is working so far, but I still have the problem, that the snippet is rendered at the top. When using your last code the bare code is rendered in the frontend. Could you assist here again, please? My current file looks like this:

```
<?php
Kirby::plugin('yourname/custom-tags', [

    'tags' => [
        'snippet' => [
            'html' => function($tag) {
                $lightboxgallery = $tag->value();
                return snippet($lightboxgallery, [], false);
            }
        ]
    ]
]);
```

---

<div class="post-metadata">

**Author:** ![Chimara2501](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@Chimara2501](https://forum.getkirby.com/u/Chimara2501)\
**Post date:** [January 8, 2021, 3:43pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/35 "2021-01-08T15:43:15Z")

</div>

Just solved it and wanted to post, if anybody else has this problem! It´s not a matter of code, it´s because of the empty lines in the snippet. Sounds strange? But it´s true: just remove the empty lines and it works! It seems that code formatting is an important thing here. Thank you anyhow for this great support!

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 8, 2021, 5:58pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/36 "2021-01-08T17:58:55Z")

</div>

> [@Chimara2501](#):
>
> Sounds strange? But it´s true: j

Yes, that’s a problem with the Parsedown library. There is already an issue to replace it one day, but…

---

<div class="post-metadata">

**Author:** ![thePhrase](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thephrase/32/10635_2.png) [@thePhrase](https://forum.getkirby.com/u/thePhrase)\
**Post date:** [February 27, 2023, 10:17am UTC](https://forum.getkirby.com/t/embedding-snippets/900/38 "2023-02-27T10:17:13Z")

</div>

I was searching for this, but I didn’t know where to look for embedded snippets in text.  
Also the information I found in the docs was a bit fragmented. I found the following:

In Kirby it’s called **KirbyTags**.

You can use tags in your texts (edited via the panel). But these text(fields) must have an extra [function so the kirbyTag gets rendered](https://getkirby.com/docs/guide/content/text-formatting#kirbytext): `->kirbytext()`.  
e.g:  
`<p><?= $block->alinea()->kirbytext() ?></p>`  
where alinea() is my fieldname that needs to be rendered.

There are [default KirbyTags](https://getkirby.com/docs/reference/#kirbytags) like (date: year) and [you can create your own tag](https://getkirby.com/docs/reference/plugins/extensions/kirbytags).

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:22pm UTC](https://forum.getkirby.com/t/embedding-snippets/900/39 "2025-02-06T17:22:53Z")

</div>

Archived on February 6, 2025, 5:22pm UTC



[Previous page](https://forum.getkirby.com/t/embedding-snippets/900.md?page=1)
