media_buttons
云策文档标注
概述
media_buttons 是一个 WordPress 动作钩子,在默认媒体按钮显示后触发,允许开发者添加自定义媒体按钮到编辑器。
关键要点
- 钩子名称:media_buttons
- 触发时机:在默认媒体按钮显示后执行
- 参数:$editor_id(字符串),唯一编辑器标识符,例如 'content'
- 源调用:do_action( 'media_buttons', $editor_id )
- 引入版本:WordPress 2.5.0
代码示例
/**
* Example of how you can add your own custom media
* button in WordPress editor
*/
function add_media_button() {
printf( '' . ' %s' . '', '#', __( 'My Custom Button', 'textdomain' ) );
}
add_action( 'media_buttons', 'add_media_button' );
原文内容
Fires after the default media button(s) are displayed.
Parameters
$editor_idstring-
Unique editor identifier, e.g.
'content'.
Source
do_action( 'media_buttons', $editor_id );
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
Skip to note 2 content
Mahfuz Rahman
/** * Example of how you can add your own custom media * button in WordPress editor */ function add_media_button() { printf( '<a href="%s" class="button my-button my-custom-button" id="my-custom-button">' . '<span class="wp-media-buttons-icon dashicons dashicons-art"></span> %s' . '</a>', '#', __( 'My Custom Button', 'textdomain' ) ); } add_action( 'media_buttons', 'add_media_button' );