21st Dec '23
/
4 comments

bricks/frontend/render_data Filter

One of the many useful filters in Bricks is bricks/frontend/render_data which allows us to modify the rendered content for different areas like header, content, and footer before it is displayed on the frontend.

This article provides examples that show how the Bricksrender_data filter can be used to automatically

  • link all occurrences of the text ACF Pro in Bricks content
  • bold all occurrences of a specific string like Company Name Inc.

Before:

After:

Add the following in child theme‘s functions.php or a code snippets plugin:

<?php 

add_filter( 'bricks/frontend/render_data', function( $content, $post, $area ) {
    // if the area of the page is not the content, return the content as is
    if ( $area !== 'content' ) {
        return $content;
    }

    // Replace every occurrence of 'ACF Pro' string with '<a href="https://advancedcustomfields.com/pro">ACF Pro</a>' in the content
    $content = str_replace( 'ACF Pro', '<a href="https://advancedcustomfields.com/pro">ACF Pro</a>', $content );

    // Return modified content
    return $content;
}, 10, 3 );

Bold all instances of a string

Before:

After:

<?php 

add_filter( 'bricks/frontend/render_data', function( $content, $post, $area ) {
    // if the area of the page is not the content, return the content as is
    if ( $area !== 'content' ) {
        return $content;
    }

    // Bold every occurrence of 'Company Name Inc.' in the content
    $content = str_replace( 'Company Name Inc.', '<strong>Company Name Inc.</strong>', $content );

    // Return modified content
    return $content;
}, 10, 3 );
Get access to all 627 Bricks code tutorials with BricksLabs Pro

4 comments

Leave a Reply to Sridhar Katakam (Cancel Reply)

 

Related Tutorials..

Pro
Setting a Bricks template for Parent pages

Setting a Bricks template for Parent pages

This Pro tutorial shows how bricks/active_templates filter can be used to programmatically assign a Bricks template to all singular pages (of any post type) that…
Pro
x Number of Random Bricks Query Loop Items(s) to be Shown Every x Hours

x Number of Random Bricks Query Loop Items(s) to be Shown Every x Hours

Showing how to display one random row of a Meta Box group for an hour and then output another random row.
Removing Action/Filter Inside a Plugin’s Namespaced Class Constructor

Removing Action/Filter Inside a Plugin’s Namespaced Class Constructor

Recently worked with a friend figuring out how to remove/undo/cancel an add_action() line that's inside a plugin's constructor inside a PHP Class with the file…
Categories:
Tags:
Pro
Conditionally Hiding Bricks Filters based on Select Filter Value

Conditionally Hiding Bricks Filters based on Select Filter Value

How show or hide Bricks' filter based on the selection made by another filter.
Categories:
Tags: