Bricks 中文文档:bricks/builder/post_title

📎 原始资料  |  下载原始 JSON 文件 (bricks-builder-post_title.json) 前言 筛选 Bricks 构建器界面中显示的文章标题(例如在搜索结果、下拉菜单和列表中)。 用法 将代码加入子主题的 functions.php: add_filter( ‘bricks/builder/post_title’, function( $title, $post_id ) { // Example: Append the post ID to the title return $title . ‘ (ID: ‘ . $post_id . ‘)’; …

前言

筛选 Bricks 构建器界面中显示的文章标题(例如在搜索结果、下拉菜单和列表中)。

用法

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

add_filter( 'bricks/builder/post_title', function( $title, $post_id ) {
    // Example: Append the post ID to the title
    return $title . ' (ID: ' . $post_id . ')';
}, 10, 2 );

参数

  • $title (string):正在编辑的文章标题。
  • $post_id (int):文章的 ID。

示例代码

筛选返回值

add_filter( 'bricks/builder/post_title', function( $title, $post_id ) {
    // Example: Append the post ID to the title
    return $title . ' (ID: ' . $post_id . ')';
}, 10, 2 );

根据条件短路返回原值

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

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

补充说明

更多细节可参考 官方文档