前言
使用此筛选器可在 Bricks 元素库中修改元素的默认设置。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/element/maybe_set_aria_current_page', function( $set_aria_current, $url ) {
// Example: Consider a link active if it matches a specific query parameter
if ( isset( $_GET['section'] ) && strpos( $url, 'section=' . $_GET['section'] ) !== false ) {
return true;
}
return $set_aria_current;
}, 10, 2 );
参数
$set_aria_current(bool):链接是否匹配当前页面。$url(string):正在被检查的链接 URL。
示例代码
筛选返回值
add_filter( 'bricks/element/maybe_set_aria_current_page', function( $set_aria_current, $url ) {
// Example: Consider a link active if it matches a specific query parameter
if ( isset( $_GET['section'] ) && strpos( $url, 'section=' . $_GET['section'] ) !== false ) {
return true;
}
return $set_aria_current;
}, 10, 2 );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/element/maybe_set_aria_current_page', function( $value, $set_aria_current ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。