前言
在 Bricks 主查询循环开始时触发。可用于在主查询循环运行开始前执行附加任务。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/get_template_authors', function( $authors ) {
// Example: Remove 'admin' from the authors list
if ( ( $key = array_search( 'admin', $authors ) ) !== false ) {
unset( $authors[ $key ] );
}
return $authors;
} );
参数
$authors(array):作者显示名称数组。
示例代码
筛选返回值
add_filter( 'bricks/get_template_authors', function( $authors ) {
// Example: Remove 'admin' from the authors list
if ( ( $key = array_search( 'admin', $authors ) ) !== false ) {
unset( $authors[ $key ] );
}
return $authors;
} );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/get_template_authors', function( $value, $authors ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。