Bricks 中文文档:bricks/popup/attributes

标签TAGS: 

📎 原始资料  |  下载原始 JSON 文件 (bricks-popup-attributes.json) 前言 筛选弹出窗口容器的 HTML 属性。允许你向弹出窗口元素添加自定义类、data 属性或其他属性。 用法 将代码加入子主题的 functions.php: add_filter( ‘bricks/popup/attributes’, function( $attributes, $popup_id ) { // Example: Add a custom class to a specific popup if ( $popup_id === 1234 ) { …

前言

筛选弹出窗口容器的 HTML 属性。允许你向弹出窗口元素添加自定义类、data 属性或其他属性。

用法

将代码加入子主题的 functions.php

add_filter( 'bricks/popup/attributes', function( $attributes, $popup_id ) {
    // Example: Add a custom class to a specific popup
    if ( $popup_id === 1234 ) {
        $attributes['class'][] = 'my-custom-popup-class';
        $attributes['data-custom-attr'] = 'value';
    }


    return $attributes;
}, 10, 2 );

参数

  • $attributes (array):HTML 属性数组(例如 class、data-popup-id)。
  • $popup_id (int):弹窗模板的 ID。

示例代码

筛选返回值

add_filter( 'bricks/popup/attributes', function( $attributes, $popup_id ) {
    // Example: Add a custom class to a specific popup
    if ( $popup_id === 1234 ) {
        $attributes['class'][] = 'my-custom-popup-class';
        $attributes['data-custom-attr'] = 'value';
    }


    return $attributes;
}, 10, 2 );

根据条件短路返回原值

根据条件跳过或修改返回值:

add_filter( 'bricks/popup/attributes', function( $value, $attributes ) {
    if ( is_admin() ) { return $value; }
    // TODO: custom logic here
    return $value;
} );

补充说明

更多细节可参考 官方文档