--- title: Hooks permalink: /docs/plugins/hooks/ --- Using hooks, your plugin can exercise fine-grained control over various aspects of the build process. If your plugin defines any hooks, Jekyll will call them at pre-defined points. Hooks are registered to an owner and an event name. To register one, you call `Jekyll::Hooks.register`, and pass the hook owner, event name, and code to call whenever the hook is triggered. For example, if you want to execute some custom functionality every time Jekyll renders a page, you could register a hook like this: ```ruby Jekyll::Hooks.register :pages, :post_render do |page| # code to call after Jekyll renders a page end ``` *Note: The `:post_convert` events mentioned hereafter is a feature introduced in v4.2.0.* Out of the box, Jekyll has pre-defined hook points for owners `:site`, `:pages`, `:documents` and `:clean`. Additionally, the hook points defined for `:documents` can be utilized for individual collections only by invoking the collection type instead. i.e. `:posts` for documents in collection `_posts` and `:movies` for documents in collection `_movies`. In all cases, Jekyll calls your hooks with the owner object as the first callback parameter. Every registered hook owner supports the following events — `:post_init`, `:pre_render`, `:post_convert`, `:post_render`, `:post_write` — however, the `:site` owner is set up to *respond* to *special event names*. Refer to the subsequent section for details. All `:pre_render` hooks and the `:site, :post_render` hook will also provide a `payload` hash as a second parameter. While in the case of `:pre_render` events, the payload gives you full control over the variables that are available during rendering, with the `:site, :post_render` event, the payload contains final values after rendering all the site (useful for sitemaps, feeds, etc). ## Built-in Hook Owners and Events The complete list of available hooks:
Owner | Event | Triggered at |
---|---|---|
Encompasses the entire site |
|
Just after the site initializes. Good for modifying the configuration of the site. Triggered once per build / serve session |
|
Just after the site resets during regeneration |
|
|
After all source files have been read and loaded from disk |
|
|
Just before rendering the whole site |
|
|
After rendering the whole site, but before writing any files |
|
|
After writing all of the rendered files to disk |
|
Allows fine-grained control over all pages in the site |
|
Whenever a page is initialized |
|
Just before rendering a page |
|
|
After converting the page content, but before rendering the page layout |
|
|
After rendering a page, but before writing it to disk |
|
|
After writing a page to disk |
|
Allows fine-grained control over all documents in the site including posts and documents in user-defined collections |
|
Whenever any document is initialized |
|
Just before rendering a document |
|
|
After converting the document content, but before rendering the document layout |
|
|
After rendering a document, but before writing it to disk |
|
|
After writing a document to disk |
|
Allows fine-grained control over all posts in the site without affecting documents in user-defined collections |
|
Whenever a post is initialized |
|
Just before rendering a post |
|
|
After converting the post content, but before rendering the postlayout |
|
|
After rendering a post, but before writing it to disk |
|
|
After writing a post to disk |
|
Fine-grained control on the list of obsolete files determined to be deleted during the site's cleanup phase. |
|
During the cleanup of a site's destination before it is built |