# Problem overriding Kirbytag

**URL:** <https://forum.getkirby.com/t/problem-overriding-kirbytag/25283>\
**Category:** Questions\
**Tags:** v3\
**Created:** [April 19, 2022, 9:25am UTC](https://forum.getkirby.com/t/problem-overriding-kirbytag/25283 "2022-04-19T09:25:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bytesource](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bytesource/32/11277_2.png) [@bytesource](https://forum.getkirby.com/u/bytesource)\
**Post date:** [April 19, 2022, 9:25am UTC](https://forum.getkirby.com/t/problem-overriding-kirbytag/25283/1 "2022-04-19T09:25:33Z")

</div>

To override the `link` Kirbytag, I wrote the following code to test the general setup:

```php
$originalTag = Kirby\Text\KirbyTag::$types['link'];

Kirby::plugin('sanofan/link-kirbytag', [
    'tags' => [
        'link' => [
            'html' => function($tag) use ($originalTag) {
                $result = $originalTag['html']($tag);
                return $result;
            }
        ],
    ],
]);

```

But now, with a link such as `(link: contact/ text: contact us)` the returned HTML is NOT

```auto
<a href="http://localhost/.../contact/">contact us</a>

```

But instead

```auto
<a href="http://localhost/.../contact/ text: contact us"></a><a href="http://localhost/.../contact/">http://localhost/zoom-petro/contact/</a> text: contact us

```

That is, the output was duplicated, and the HTML of the second link is messed up.

I’m using Kirby version 3.6.1.1 with PHP version 8.0.13 on localhost.

Do you have any idea what went wrong here?

Cheers,

Stefan

---

<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 19, 2022, 12:08pm UTC](https://forum.getkirby.com/t/problem-overriding-kirbytag/25283/2 "2022-04-19T12:08:21Z")

</div>

That happens because the attributes are not defined:

```auto
<?php
$originalTag = Kirby\Text\KirbyTag::$types['link'];

Kirby::plugin('sanofan/link-kirbytag', [
    'tags' => [
        'link' => [
            'attr' => $originalTag['attr'],
            'html' => function($tag) use ($originalTag) {
                $result = $originalTag['html']($tag);
                return $result;
            }
        ],
    ],
]);

```

---

<div class="post-metadata">

**Author:** ![bytesource](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bytesource/32/11277_2.png) [@bytesource](https://forum.getkirby.com/u/bytesource)\
**Post date:** [April 20, 2022, 2:35am UTC](https://forum.getkirby.com/t/problem-overriding-kirbytag/25283/3 "2022-04-20T02:35:19Z")

</div>

Thanks a lot, that works perfectly!

So, if I use the same name as a built-in kirbytag in a plugin, such as `link` in this case, Kirby will use the plugin code exclusively, allowing me to use parts of the original kirbytag logic via `Kirby\Text\KirbyTag::$types['link']`.

Is this correct?

---

<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 20, 2022, 6:40am UTC](https://forum.getkirby.com/t/problem-overriding-kirbytag/25283/4 "2022-04-20T06:40:42Z")

</div>

Yes, you can reuse the original, but it probably only makes sense in limited use cases. Usually, you will either want to add new attributes or change the html, then it’s probably better to copy the code from the original tag and make your mods where necessary.

---

<div class="post-metadata">

**Author:** ![bytesource](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bytesource/32/11277_2.png) [@bytesource](https://forum.getkirby.com/u/bytesource)\
**Post date:** [April 20, 2022, 6:59am UTC](https://forum.getkirby.com/t/problem-overriding-kirbytag/25283/5 "2022-04-20T06:59:39Z")

</div>

Thanks, that makes sense.
