Bricks 中文文档:bricks/elements/{element_name}/scripts

📎 原始资料  |  下载原始 JSON 文件 (bricks-elements-element_name-scripts.json) 前言 此筛选器允许你从 Bricks 元素库中移除一个或多个元素。 用法 将代码加入子主题的 functions.php: // Filter scripts for the ‘slider’ element add_filter( ‘bricks/elements/slider/scripts’, function( $scripts ) { // Add a custom script dependency $scripts[] = ‘…

前言

此筛选器允许你从 Bricks 元素库中移除一个或多个元素。

用法

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

// Filter scripts for the 'slider' element
add_filter( 'bricks/elements/slider/scripts', function( $scripts ) {
    // Add a custom script dependency
    $scripts[] = 'my-custom-slider-script';


    return $scripts;
} );

参数

  • $scripts (array):通过 wp_register_script 注册的脚本句柄数组。

示例代码

筛选返回值

// Filter scripts for the 'slider' element
add_filter( 'bricks/elements/slider/scripts', function( $scripts ) {
    // Add a custom script dependency
    $scripts[] = 'my-custom-slider-script';


    return $scripts;
} );

根据条件短路返回原值

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

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

补充说明

更多细节可参考 官方文档