百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

themehookalliance

> 编程语言
开源

主题钩子 -- 我们来开始吧!

367 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

主题钩子 -- 我们来开始吧!

Theme Hook Alliance

Status

1.0

What?

Child theme authors and plugin developers need a consistent set of entry points to allow for easy customization and altering of functionality. Core WordPress offers a suite of action hooks and template tags but does not cover many of the common use cases. The Theme Hook Alliance is a community-driven effort to agree on a set of third-party action hooks that THA themes pledge to implement in order to give that desired consistency.

Why?

There have been discussions about implementing a common set of hooks, a Trac ticket and even an initial pass at implementing something similar. However, for whatever reason[s], these efforts have not gained traction. I proposed this third-party solution here and this project is intended to be an implementation of these goals.

What about WordPress?

As stated above, there have been attempts to have something along these lines added to WordPress Core in the past and, while they have generally been seen as good ideas, they have remained as such.

Taking this out of the realm of Core and into the third-party realm is a bit of a risky proposition, to be sure. If the conventions laid out below are not adopted in a widespread fashion, this effort will ultimately fail.

However, this is no reason to wait. Child themes have recently been approved for release in the official Themes Repository and plugin authors continue to need more reliable entry points into WordPress' content flow so as to avoid nasty hacks like output buffering.

When Core does it, Core wins

A small note: none of the proposed theme hooks are intended to replace or rewrite existing WordPress functionality. So, for instance, if a desired result can be obtained by filtering the output of e.g. the_content(), there is no need to create an entirely new hook. Therefore, any functions that duplicate work Core performs already should be rejected immediately.

What if Core adds some (or all) of these filters?

If this idea gains enough traction, there is a chance that a partial, or even full, portion of these hooks will make their way into Core. When/if this occurs, we can simply update tha-theme-hooks.php to include the new do_action() calls at the appropriate places. Then, THA users will simply need to update their copy of tha-theme-hooks.php to take advantage.

For example, if Core were to introduce a before_header hook, we could (in theory) simply alter tha_header_before as follows

php
	function tha_header_before() {
		do_action( 'tha_header_before' );
		do_action( 'before_header' );
	}

This would allow all themes using the THA hooks to avoid rewriting/refactoring in the case of a Core change.

Conventions

  • Hooks should be of the form tha_ + [section of the theme] + _[placement within block].
  • Hooks should be named based upon the generally-accepted semantic name for the section of a theme they cover, e.g., tha_content_* should refer to the section/block of a theme containing the content (or "The Loop"), while tha_sidebar_* would refer to the sidebars generally called by get_sidebar().
  • Hooks should be suffixed based upon their placement within a block.
    • Hooks immediately preceding a block should use _before.
    • Hooks immediately following a block should use _after.
    • Hooks placed at the very beginning of a block should use _top.
    • Hooks placed at the very end of a block should use _bottom.
  • If the theme section covered by a hook can contain multiple semantic elements, it should be pluralized. (Primarily applies to tha_sidebars_before/after in the early goings.)

Usage

  1. Copy tha-theme-hooks.php to a directory inside of your theme; say, include/, for instance.
  2. Include tha-theme-hooks.php via `` in your functions.php or similar.
  3. Using tha-example-index.php as a guide, be sure to implement all of the hooks described in tha-theme-hooks.php in order to offer full compatibility.
  4. Profit!

Core Compatibility

Working on it!

THA-Compatible Themes

  • In-Progress

    • Elbee Elgee by Doug Stewart (bitbucket)
  • Full Support

    • The Bootstrap by Konstantin Obenland (github)
    • wolf by Brad Parbs (github)
    • hook_s by Brad Parbs (github)
    • Documentation by Frank Bültge
    • Opus Primus (via a Stanza) by Cais (github)
    • Oenology by Chip Bennett (github)
    • Museum Core by Chris Reynolds (github)
    • Decode by Scott Smith (github)
    • Some Like It Neat by Alex Vasquez
    • Compass by Flagship
    • Tiny Framework by Tomas Mackevicius

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言