# How to trigger a hook via link

**URL:** <https://forum.getkirby.com/t/how-to-trigger-a-hook-via-link/30081>\
**Category:** Questions\
**Tags:** v3\
**Created:** [November 23, 2023, 9:48pm UTC](https://forum.getkirby.com/t/how-to-trigger-a-hook-via-link/30081 "2023-11-23T21:48:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![konst](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@konst](https://forum.getkirby.com/u/konst)\
**Post date:** [November 23, 2023, 9:48pm UTC](https://forum.getkirby.com/t/how-to-trigger-a-hook-via-link/30081/1 "2023-11-23T21:48:31Z")

</div>

Hello,  
I have implemented the plugin “[kirby-locked-pages](https://github.com/johannschopplich/kirby-locked-pages)” but I am stuck on a question about hooks.

The plugin contains a hook ‘locked-pages.logout’ which allows to logout again. But I don’t understand how to trigger a kirby hook via a html-link.

For example:

```auto
<a click="<?= $kirby->trigger('locked-pages.logout') ?>" href="">Logout</a>

```

Using this code already triggers the hook on page load.  
So how do I trigger the hook after clicking the link?

---

<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:** [November 24, 2023, 8:14pm UTC](https://forum.getkirby.com/t/how-to-trigger-a-hook-via-link/30081/2 "2023-11-24T20:14:53Z")

</div>

You cannot trigger a hook via a link, or not directly. The easiest would be a custom route, with a pattern like `logout`, then inside this route, call  
`kirby()->trigger('locked-pages.logout')`. Not sure why a hook is used.

---

<div class="post-metadata">

**Author:** ![konst](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@konst](https://forum.getkirby.com/u/konst)\
**Post date:** [November 24, 2023, 9:28pm UTC](https://forum.getkirby.com/t/how-to-trigger-a-hook-via-link/30081/3 "2023-11-24T21:28:24Z")

</div>

Thank you for your comment,

I also was asking myself why a hook is used.  
I will give it a try with a custom route.

---

<div class="post-metadata">

**Author:** ![konst](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@konst](https://forum.getkirby.com/u/konst)\
**Post date:** [November 25, 2023, 6:41pm UTC](https://forum.getkirby.com/t/how-to-trigger-a-hook-via-link/30081/4 "2023-11-25T18:41:41Z")

</div>

I somehow managed to trigger that hook by creating a new route which I call via link. But somehow I have to click that link twice to call that route.

On first click kirby redirects me to the website’s error page.  
Only on second click the route seems to be followed.

Here is my route:

```auto
    [
        'pattern' => '/logout/(:all)',
        'language' => '*',
        'action' => function () {
            kirby()->trigger('locked-pages.logout');
            go('home');
        }
    ]

```

This is my link:

```auto
<a href="logout/">Logout</a>

```

I surely misunderstand routing but it almost seems to work, so I think this can’t be competely wrong.

And suggestions?

P.S. I contacted the developer of this plugin, unfortunately he doesn’t have time to help.
