Bricks 中文文档:bricks/database/content_type

📎 原始资料  |  下载原始 JSON 文件 (bricks-database-content_type.json) 前言 修改 Bricks Builder 中可用的 CSS 断点。 用法 将代码加入子主题的 functions.php: add_filter( ‘bricks/database/content_type’, function( $content_type, $post_id ) { // Example: Treat a specific page as a search results page if ( is_page( ‘advanced-sea…

前言

修改 Bricks Builder 中可用的 CSS 断点。

用法

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

add_filter( 'bricks/database/content_type', function( $content_type, $post_id ) {
    // Example: Treat a specific page as a search results page
    if ( is_page( 'advanced-search' ) ) {
        return 'search';
    }


    return $content_type;
}, 10, 2 );

参数

  • $content_type (string):检测到的内容类型(例如 content、archive、search、error、header、footer)。
  • $post_id (int):当前文章 ID。

示例代码

筛选返回值

add_filter( 'bricks/database/content_type', function( $content_type, $post_id ) {
    // Example: Treat a specific page as a search results page
    if ( is_page( 'advanced-search' ) ) {
        return 'search';
    }


    return $content_type;
}, 10, 2 );

根据条件短路返回原值

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

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

补充说明

更多细节可参考 官方文档