disable_captions
云策文档标注
概述
本文档介绍了 WordPress 中的 'disable_captions' 过滤器,用于控制是否在编辑器中插入图像时禁用图像标题的附加。该过滤器允许开发者通过返回布尔值来动态管理标题的显示。
关键要点
- 'disable_captions' 是一个过滤器,用于决定是否禁用图像标题的附加。
- 过滤器参数为布尔值 $bool,返回 true 将禁用标题,默认值为空字符串。
- 该过滤器在 WordPress 2.6.0 版本中引入,影响图像插入到编辑器时的行为。
- 相关函数包括 wp_tinymce_inline_scripts()、image_add_caption() 等,用于媒体处理和编辑器集成。
代码示例
// 禁用所有图像的标题
add_filter( 'disable_captions', '__return_true' );
// 在特定页面(如首页)禁用标题
function generatewp_caption_disabler() {
if ( is_home() ) {
return true;
} else {
return false;
}
}
add_filter( 'disable_captions', 'generatewp_caption_disabler' );
原文内容
Filters whether to disable captions.
Description
Prevents image captions from being appended to image HTML when inserted into the editor.
Parameters
$boolbool-
Whether to disable appending captions. Returning true from the filter will disable captions. Default empty string.
Source
if ( empty( $caption ) || apply_filters( 'disable_captions', '' ) ) {
Changelog
| Version | Description |
|---|---|
| 2.6.0 | Introduced. |
Skip to note 2 content
Rami Yushuvaev
Disable captions from all the images:
add_filter( 'disable_captions', '__return_true' );Disable captions from images in specific pages:
function generatewp_caption_disabler() { if ( is_home() ) { return true; } else { return false; } } add_filter( 'disable_captions', 'generatewp_caption_disabler' );