Fork me on GitHub

Ready to contribute?

Amazing! Sign our contributors' agreement and then join us on GitHub.

You should grab 2.1.9, released 18 March. It's what all the cool kids are doing.

Theme Hooks

Every theme can have a hooks file which lets you add programmatic functionality to your theme. This file is a plugin and can do whatever a plugin can do.

Creating The Hooks File

To create a theme hooks file do the following.

  1. In your plugin folder add a file called class.[pluginname]themehooks.php. Where [pluginname] is the name of your plugin. Make sure the filename is all lowercase.
  2. Add a class in the hooks file that extends Gdn_Plugin:
    class [PluginName]ThemeHooks extends Gdn_Plugin {
  3. Add event handlers to your theme hooks file.
  4. Make sure you disable an re-enable your theme when you first add your theme hooks file.

That's it! Your theme hooks file will be recognized when your theme is enabled.

Tips & Tricks

  • Usually, you use the theme hooks file to add bits of html inside the various pages.
  • The Eventi plugin is a great way to see all of the events that you can put in your hooks file.
Edited June 2011 by Todd