elementor-hooks
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseElementor Hooks Reference
Elementor 钩子参考文档
1. PHP Action Hooks
1. PHP 动作钩子
Lifecycle
生命周期
| Hook Name | Parameters | Description |
|---|---|---|
| none | Fires when Elementor plugin is loaded, before components initialize. Use for checking Elementor availability. |
| none | Fires when Elementor is fully loaded. Use for registering custom functionality. |
| 钩子名称 | 参数 | 描述 |
|---|---|---|
| 无 | 当Elementor插件加载完成、组件初始化前触发。用于检查Elementor是否可用。 |
| 无 | 当Elementor完全加载完成后触发。用于注册自定义功能。 |
Registration
注册相关
| Hook Name | Parameters | Description |
|---|---|---|
| | Register custom widgets |
| | Register custom controls |
| | Register dynamic tags |
| | Register Finder categories |
| | Register widget categories |
| | Register document types |
| 钩子名称 | 参数 | 描述 |
|---|---|---|
| | 注册自定义小部件 |
| | 注册自定义控件 |
| | 注册动态标签 |
| | 注册Finder分类 |
| | 注册小部件分类 |
| | 注册文档类型 |
Frontend Scripts and Styles
前端脚本与样式
| Hook Name | Parameters | Description |
|---|---|---|
| none | After frontend scripts registered |
| none | Before frontend scripts registered |
| none | After frontend styles registered |
| none | Before frontend styles registered |
| none | After frontend scripts enqueued |
| none | Before frontend scripts enqueued |
| none | After frontend styles enqueued |
| none | Before frontend styles enqueued |
| 钩子名称 | 参数 | 描述 |
|---|---|---|
| 无 | 前端脚本注册完成后触发 |
| 无 | 前端脚本注册前触发 |
| 无 | 前端样式注册完成后触发 |
| 无 | 前端样式注册前触发 |
| 无 | 前端脚本入队完成后触发 |
| 无 | 前端脚本入队前触发 |
| 无 | 前端样式入队完成后触发 |
| 无 | 前端样式入队前触发 |
Editor Scripts and Styles
编辑器脚本与样式
| Hook Name | Parameters | Description |
|---|---|---|
| none | Before editor scripts enqueued |
| none | After editor scripts enqueued |
| none | After editor styles enqueued |
| none | Before editor styles enqueued |
| 钩子名称 | 参数 | 描述 |
|---|---|---|
| 无 | 编辑器脚本入队前触发 |
| 无 | 编辑器脚本入队完成后触发 |
| 无 | 编辑器样式入队完成后触发 |
| 无 | 编辑器样式入队前触发 |
Preview Scripts and Styles
预览脚本与样式
| Hook Name | Parameters | Description |
|---|---|---|
| none | Enqueue scripts in the preview iframe |
| none | Enqueue styles in the preview iframe |
| 钩子名称 | 参数 | 描述 |
|---|---|---|
| 无 | 在预览iframe中入队脚本 |
| 无 | 在预览iframe中入队样式 |
Widget Rendering
小部件渲染
| Hook Name | Parameters | Description |
|---|---|---|
| | Register custom skins for a widget |
| | Before widget content renders |
| | Before any element renders (all types) |
| | After any element renders (all types) |
| | Before specific element type renders |
| | After specific element type renders |
Element types for : , , ,
{$element_type}sectioncolumncontainerwidget| 钩子名称 | 参数 | 描述 |
|---|---|---|
| | 为小部件注册自定义皮肤 |
| | 小部件内容渲染前触发 |
| | 任意元素渲染前触发(所有类型) |
| | 任意元素渲染后触发(所有类型) |
| | 指定类型元素渲染前触发 |
| | 指定类型元素渲染后触发 |
{$element_type}sectioncolumncontainerwidgetDocument and Editor Save
文档与编辑器保存
| Hook Name | Parameters | Description |
|---|---|---|
| | Register controls for documents/page settings |
| | After user saves editor data |
| | Before document saves |
| | After document saves |
| 钩子名称 | 参数 | 描述 |
|---|---|---|
| | 为文档/页面设置注册控件 |
| | 用户保存编辑器数据后触发 |
| | 文档保存前触发 |
| | 文档保存后触发 |
CSS File Hooks
CSS文件钩子
| Hook Name | Parameters | Description |
|---|---|---|
| | Add custom CSS rules to element CSS |
| | Before CSS is parsed |
| | When a CSS file is enqueued |
| none | When CSS cache is cleared |
| 钩子名称 | 参数 | 描述 |
|---|---|---|
| | 为元素CSS添加自定义CSS规则 |
| | CSS解析前触发 |
| | CSS文件入队时触发 |
| 无 | CSS缓存清除时触发 |
Forms (Pro)
表单(Pro版)
| Hook Name | Parameters | Description |
|---|---|---|
| | Validate all form fields |
| | Validate specific field type |
| | After fields validated, process form |
| | Process specific field type |
| | After form actions run |
| | When form POST received |
| | After form email sent |
| | Handle webhook response |
| 钩子名称 | 参数 | 描述 |
|---|---|---|
| | 验证所有表单字段 |
| | 验证指定类型的字段 |
| | 字段验证通过后,处理表单 |
| | 处理指定类型的字段 |
| | 表单动作执行完成后触发 |
| | 收到表单POST请求时触发 |
| | 表单邮件发送完成后触发 |
| | 处理Webhook响应 |
Query (Pro)
查询(Pro版)
| Hook Name | Parameters | Description |
|---|---|---|
| | Filter Posts/Portfolio widget query. Set Query ID in widget settings. |
| 钩子名称 | 参数 | 描述 |
|---|---|---|
| | 过滤文章/作品集小部件的查询。需在小部件设置中配置Query ID。 |
Other Important Actions
其他重要动作钩子
| Hook Name | Parameters | Description |
|---|---|---|
| | Register AJAX handlers |
| none | Editor initialization |
| none | Editor footer output |
| none | Preview initialization |
| | Register kit (site settings) tabs |
| none | Before canvas template content |
| none | After canvas template content |
| | After template saved |
| | After render attributes added |
| | Register experiments |
| 钩子名称 | 参数 | 描述 |
|---|---|---|
| | 注册AJAX处理器 |
| 无 | 编辑器初始化时触发 |
| 无 | 编辑器页脚输出时触发 |
| 无 | 预览初始化时触发 |
| | 注册工具包(站点设置)标签页 |
| 无 | 画布模板内容输出前触发 |
| 无 | 画布模板内容输出后触发 |
| | 模板保存完成后触发 |
| | 渲染属性添加完成后触发 |
| | 注册实验功能 |
2. PHP Filter Hooks
2. PHP 过滤器钩子
Widget Output Filters
小部件输出过滤器
| Filter Name | Parameters | Description |
|---|---|---|
| | Filter widget HTML on frontend |
| | Filter widget JS template in preview |
| | Filter entire Elementor page output |
| | Control whether element renders |
| 过滤器名称 | 参数 | 描述 |
|---|---|---|
| | 在前端过滤小部件的HTML内容 |
| | 在预览中过滤小部件的JS模板 |
| | 过滤整个Elementor页面的输出内容 |
| | 控制元素是否渲染 |
Document and Config Filters
文档与配置过滤器
| Filter Name | Parameters | Description |
|---|---|---|
| | Filter document config |
| | Filter data before save |
| | Filter edit URL |
| | Filter preview URL |
| | Filter editor localized settings |
| 过滤器名称 | 参数 | 描述 |
|---|---|---|
| | 过滤文档配置 |
| | 保存前过滤文档数据 |
| | 过滤编辑页面URL |
| | 过滤预览页面URL |
| | 过滤编辑器本地化设置 |
Visual Element Filters
视觉元素过滤器
| Filter Name | Parameters | Description |
|---|---|---|
| | Return false to disable Google Fonts loading |
| | Add custom shape dividers |
| | Add custom mask shapes |
| | Change default placeholder image |
| | Add custom icon libraries |
| | Add custom fonts |
| | Add custom animations |
| | Add custom divider styles |
| 过滤器名称 | 参数 | 描述 |
|---|---|---|
| | 返回false可禁用Google Fonts加载 |
| | 添加自定义形状分隔符 |
| | 添加自定义遮罩形状 |
| | 修改默认占位图片 |
| | 添加自定义图标库 |
| | 添加自定义字体 |
| | 添加自定义动画 |
| | 添加自定义分隔线样式 |
Finder and Template Filters
Finder与模板过滤器
| Filter Name | Parameters | Description |
|---|---|---|
| | Add/modify Finder categories |
| | Filter template data |
| | Control template export |
| | Allow unfiltered file uploads |
| | Enable/disable SVG support |
| 过滤器名称 | 参数 | 描述 |
|---|---|---|
| | 添加/修改Finder分类 |
| | 过滤模板数据 |
| | 控制模板是否支持导出 |
| | 允许上传未经过滤的文件 |
| | 启用/禁用SVG支持 |
Forms Filters (Pro)
表单过滤器(Pro版)
| Filter Name | Parameters | Description |
|---|---|---|
| | Filter form email headers |
| | Filter form email body HTML |
| | Override custom fonts |
| 过滤器名称 | 参数 | 描述 |
|---|---|---|
| | 过滤表单邮件头 |
| | 过滤表单邮件正文HTML |
| | 覆盖自定义字体的 |
Other Important Filters
其他重要过滤器
| Filter Name | Parameters | Description |
|---|---|---|
| | Filter builder content data |
| | Filter frontend assets URL |
| | Widget class blacklist |
| | Filter allowed child types |
| | Filter post type support |
| 过滤器名称 | 参数 | 描述 |
|---|---|---|
| | 过滤构建器内容数据 |
| | 过滤前端资源URL |
| | 小部件类黑名单 |
| | 过滤允许的子元素类型 |
| | 过滤自定义文章类型支持 |
3. Injecting Controls
3. 注入控件
Targeting All Elements
针对所有元素
Inject controls into every element using these hooks:
| Hook Name | Params | Use |
|---|---|---|
| | Add new section before an existing section |
| | Add control inside start of existing section |
| | Add control inside end of existing section |
| | Add new section after an existing section |
使用以下钩子可向所有元素注入控件:
| 钩子名称 | 参数 | 用途 |
|---|---|---|
| | 在现有区块前添加新区块 |
| | 在现有区块开头添加控件 |
| | 在现有区块结尾添加控件 |
| | 在现有区块后添加新区块 |
Targeting Specific Elements
针对特定元素
Use and to target a specific widget and section:
{$stack_name}{$section_id}| Hook Pattern | Params | Use |
|---|---|---|
| | Add section before |
| | Add control at section start |
| | Add control at section end |
| | Add section after |
See for code examples.
resources/injecting-controls-examples.md使用和可定位到特定小部件和区块:
{$stack_name}{$section_id}| 钩子模式 | 参数 | 用途 |
|---|---|---|
| | 在目标区块前添加新区块 |
| | 在目标区块开头添加控件 |
| | 在目标区块结尾添加控件 |
| | 在目标区块后添加新区块 |
代码示例请参考。
resources/injecting-controls-examples.md4. JS Frontend Hooks
4. 前端JS钩子
Frontend hooks use (available on the frontend page).
elementorFrontend.hooks前端钩子使用(在前端页面中可用)。
elementorFrontend.hooksActions
动作钩子
| Hook Name | Parameters | Description |
|---|---|---|
| none | Frontend initialized |
| | Any element is ready (sections, columns, widgets) |
| | Any widget is ready |
| | Specific widget+skin is ready (e.g. |
| 钩子名称 | 参数 | 描述 |
|---|---|---|
| 无 | 前端初始化完成后触发 |
| | 任意元素准备就绪时触发(区块、列、小部件) |
| | 任意小部件准备就绪时触发 |
| | 指定小部件+皮肤准备就绪时触发(例如 |
Filters
过滤器钩子
| Hook Name | Parameters | Description |
|---|---|---|
| | Adjust scroll distance for menu anchors |
See for code examples.
resources/js-hooks-commands.md| 钩子名称 | 参数 | 描述 |
|---|---|---|
| | 调整菜单锚点的滚动距离 |
代码示例请参考。
resources/js-hooks-commands.md5. JS Editor Hooks
5. 编辑器JS钩子
Editor hooks use (available inside the Elementor editor).
elementor.hooks编辑器钩子使用(在Elementor编辑器内可用)。
elementor.hooksActions
动作钩子
| Hook Name | Parameters | Description |
|---|---|---|
| | Settings panel opened for element type ( |
| | Settings panel opened for a specific widget name |
| 钩子名称 | 参数 | 描述 |
|---|---|---|
| | 为指定类型元素打开设置面板时触发( |
| | 为指定名称的小部件打开设置面板时触发 |
Filters
过滤器钩子
| Hook Name | Parameters | Description |
|---|---|---|
| | Modify right-click context menu groups |
See for code examples.
resources/js-hooks-commands.md| 钩子名称 | 参数 | 描述 |
|---|---|---|
| | 修改右键上下文菜单分组 |
代码示例请参考。
resources/js-hooks-commands.md6. JS Commands API ($e.commands
)
$e.commands6. JS 命令API($e.commands
)
$e.commandsThe Commands API (since 2.7.0) manages all editor commands. Run commands with .
$e.run()命令API(2.7.0版本起)用于管理所有编辑器命令。使用执行命令。
$e.run()Key Methods
核心方法
| Method | Parameters | Returns | Description |
|---|---|---|---|
| | | Register a new command |
| | | Execute a command |
| none | | Get all registered commands |
| none | | Get currently running commands |
| | | Check if command is currently running |
| none | | Get args of currently running command |
| none | | Get first currently running command |
| 方法 | 参数 | 返回值 | 描述 |
|---|---|---|---|
| | | 注册新命令 |
| | | 执行命令 |
| 无 | | 获取所有已注册命令 |
| 无 | | 获取当前正在执行的命令 |
| | | 检查指定命令是否正在执行 |
| 无 | | 获取当前执行命令的参数 |
| 无 | | 获取当前正在执行的第一个命令 |
Command Types
命令类型
| Base Class | Type | Purpose |
|---|---|---|
| User commands | Represent user actions |
| Internal commands | For internal editor use |
| Data commands | Communicate with data/cache/backend |
See for full code examples.
resources/js-hooks-commands.md| 基类 | 类型 | 用途 |
|---|---|---|
| 用户命令 | 代表用户操作 |
| 内部命令 | 供编辑器内部使用 |
| 数据命令 | 用于与数据/缓存/后端通信 |
完整代码示例请参考。
resources/js-hooks-commands.md7. JS Components API ($e.components
)
$e.components7. JS 组件API($e.components
)
$e.components| Method | Parameters | Returns | Description |
|---|---|---|---|
| | | Register a component |
| | | Get component by namespace |
| none | | Get all components |
| | Activate a component | |
| | Deactivate a component | |
| | | Check if component is active |
| none | | Get all active components |
A component serves as a namespace that holds commands, hooks, routes, tabs, shortcuts, and utils. Component class files should be named .
component.jsSee for code examples.
resources/js-hooks-commands.md| 方法 | 参数 | 返回值 | 描述 |
|---|---|---|---|
| | | 注册组件 |
| | | 通过命名空间获取组件 |
| 无 | | 获取所有组件 |
| | 激活组件 | |
| | 停用组件 | |
| | | 检查组件是否处于激活状态 |
| 无 | | 获取所有激活状态的组件 |
组件作为命名空间,用于存储命令、钩子、路由、标签页、快捷键和工具函数。组件类文件应命名为。
component.js代码示例请参考。
resources/js-hooks-commands.md8. JS Hooks API ($e.hooks
)
$e.hooks8. JS 钩子API($e.hooks
)
$e.hooksThe API manages hooks that fire before/after commands run via .
$e.hooks$e.run()$e.hooks$e.run()UI Hooks
UI钩子
| Method | Parameter | Description |
|---|---|---|
| | Before command runs (UI) |
| | After command runs (UI) |
| | When command fails (UI) |
| 方法 | 参数 | 描述 |
|---|---|---|
| | 命令执行前触发(UI相关) |
| | 命令执行后触发(UI相关) |
| | 命令执行失败时触发(UI相关) |
Data Hooks
数据钩子
| Method | Parameter | Description |
|---|---|---|
| | Before command (dependency check) |
| | After command runs (data) |
| | When command fails (data) |
See for hook convention code examples and import patterns.
resources/js-hooks-commands.md| 方法 | 参数 | 描述 |
|---|---|---|
| | 命令执行前触发(依赖检查) |
| | 命令执行后触发(数据相关) |
| | 命令执行失败时触发(数据相关) |
钩子规范代码示例和导入模式请参考。
resources/js-hooks-commands.md9. Common Patterns
9. 常见使用场景
| I want to... | Use this hook |
|---|---|
| Register a custom widget | |
| Register a custom control | |
| Add a widget category | |
| Register a dynamic tag | |
| Enqueue frontend script | |
| Enqueue editor script | |
| Enqueue preview script | |
| Add control to existing widget | |
| Add control to page settings | |
| Add control to user preferences | |
| Modify widget HTML output | |
| Modify widget JS template | |
| Filter entire page output | |
| Disable Google Fonts | |
| Change placeholder image | |
| Add custom shape dividers | |
| Add custom mask shapes | |
| Validate form data (Pro) | |
| Process form after submit (Pro) | |
| Filter posts widget query (Pro) | |
| Add CSS rules to elements | |
| Run code when widget ready (JS) | |
| Hook into editor panel open (JS) | |
| Register editor command (JS) | |
| Hook before/after command (JS) | |
| 我想要... | 使用此钩子 |
|---|---|
| 注册自定义小部件 | |
| 注册自定义控件 | |
| 添加小部件分类 | |
| 注册动态标签 | |
| 入队前端脚本 | |
| 入队编辑器脚本 | |
| 入队预览脚本 | |
| 向现有小部件添加控件 | |
| 向页面设置添加控件 | |
| 向用户偏好设置添加控件 | |
| 修改小部件HTML输出 | |
| 修改小部件JS模板 | |
| 过滤整个页面输出 | |
| 禁用Google Fonts | |
| 修改占位图片 | |
| 添加自定义形状分隔符 | |
| 添加自定义遮罩形状 | |
| 验证表单数据 (Pro版) | |
| 提交后处理表单 (Pro版) | |
| 过滤文章小部件查询 (Pro版) | |
| 为元素添加CSS规则 | |
| 小部件准备就绪时执行代码(JS) | 通过 |
| 编辑器面板打开时触发(JS) | 通过 |
| 注册编辑器命令(JS) | |
| 命令执行前后触发钩子(JS) | |