Using Hooks
Hooks are a simple way to make Pure Blog do extra things when something changes on your site. Think of them like little trip‑wires: when a post is published, updated, or deleted, you can run your own code.
You don’t need a plugin system or any complicated setup. Just drop a small file into config/hooks.php, define the hook functions you care about, and Pure Blog will call them when the matching event happens.
What can hooks do?
Here are a few examples of what people typically use hooks for:
- Clear your CDN cache (Bunny, Cloudflare, etc.)
- Ping search engines or IndexNow
- Post to Mastodon, Bluesky, or X when you publish
- Send yourself a notification when something goes live
- Trigger a webhook (Zapier, Make, your own API)
- Rebuild a static index or sitemap
How hooks work
Hooks are just regular PHP functions. If a function exists, Pure Blog will call it. If it doesn’t, nothing happens.
For example, you can add this to config/hooks.php:
<?php
function on_post_published(string $slug): void
{
// do something here
}
When you publish a post, Pure Blog will call that function and pass the post slug.
Available hook events
At the moment, Pure Blog supports these events:
on_post_published($slug)on_post_updated($slug)on_post_deleted($slug)on_page_published($slug)on_page_updated($slug)on_page_deleted($slug)
You can implement any or all of them, it’s entirely optional. /config/hook-example.php is included with Pure Blog, which is a working example that adds support for clearing cache with Bunny CDN whenever a post/page is published, updated, or deleted. Just enter the API and Zone ID at the top.
If your source code is published to a repository like GitHub, please ensure hook.php is added to your .gitignore file.
This feature is intentionally simple. It gives you power without dragging a full plugin system into the core. If you want more structure later, you can build on top of it.