Premium add-on for Bricks Builder

Style Bricks Post State text

Someone asked this question in the Bricks Community FB group

Hi guys, is it possible to stylize “Bricks” in pages as in the picture? In the css there is only a generic class “post-state”. I have a site with several pages managed with both Gutenberg or Bricks and would like to make it more obvious where Bricks Builder is used.

Open the functions.php file of the Bricks child theme or add this small PHP code in 3rd party snippets plugin.

add_filter( 'display_post_states', 'bu_style_post_state_bricks', 15, 2 );
function bu_style_post_state_bricks ($post_states, $post) {
    if( isset( $post_states['bricks'] ) ) {
        if( current_user_can( 'edit_posts', $post->ID ) ) {
            $bricks_edit_link = get_permalink($post->ID) . '?bricks=run';
            $post_states['bricks'] = '<a href="' . $bricks_edit_link . '" rel="nofollow ugc" style="background-color:#fcd568; padding: 4px 6px;color:#444">' . $post_states['bricks'] . '</a>';
        } else {
            $post_states['bricks'] = '<span style="background-color:#fcd568; padding: 4px 6px">' . $post_states['bricks'] . '</span>';
        }
    }

    return $post_states;
}
Fills In: 

4 comments

  • Doesn’t do anything for me.

    Where is the styling coming from? I don’t see any css or styling attached to this snippet.

    • A

      You are right. The style was missing in the last updated code. I updated the code again. Now you will update the code and style will come.

  • Modified version with a link to edit in bricks, and checking if the user has rights to edit posts :


    add_filter( 'display_post_states', 'bu_style_post_state_bricks', 15, 2 );
    function bu_style_post_state_bricks ($post_states, $post) {
    if( isset( $post_states['bricks'] ) ) {
    if( current_user_can( 'edit_posts', $post->ID ) ) {
    $bricks_edit_link = get_permalink($post->ID) . '?bricks=run';
    $post_states['bricks'] = '' . $post_states['bricks'] . '';
    } else {
    $post_states['bricks'] = '' . $post_states['bricks'] . '';
    }
    }

    return $post_states;
    }

Leave a Reply to Tonio (Cancel Reply)

Search Tutorials

Request TutorialsFeatures Request