is_embed()
云策文档标注
概述
is_embed() 是一个 WordPress 条件标签函数,用于检查当前查询是否为嵌入式文章。它返回布尔值,并依赖于全局 $wp_query 对象。
关键要点
- 函数返回布尔值,指示查询是否为嵌入式文章。
- 在查询运行前调用会触发 _doing_it_wrong() 警告并返回 false。
- 内部调用 $wp_query->is_embed() 方法。
代码示例
function is_embed() {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return false;
}
return $wp_query->is_embed();
}注意事项
- 避免在查询运行前使用此函数,否则会返回 false 并记录错误。
- 相关函数包括 WP_Query::is_embed()、__() 和 _doing_it_wrong()。
原文内容
Is the query for an embedded post?
Source
function is_embed() {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return false;
}
return $wp_query->is_embed();
}
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |