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 626 Bricks code tutorials with BricksLabs Pro

4 comments

Leave a Reply to Michael (Cancel Reply)

 

Related Tutorials..

Show Product Categories Count Using Bricks Filter Hook

Show Product Categories Count Using Bricks Filter Hook

Unable to find terms count from the Dynamic Data provided by Bricks theme? It's okay, this simple tutorial shows you how to properly get the…
Categories:
Tags:
How to hide/remove the Block Element from the Bricks Builder

How to hide/remove the Block Element from the Bricks Builder

Don't like the new Block element in Bricks? Just copy/paste the following code into your child theme's functions.php. By the way, It's a terrible idea…
Categories:
Tags:
Pro
Programmatically populating ACF field values in WordPress

Programmatically populating ACF field values in WordPress

An example of how to set the values of a Select-type field with the names and labels of all public post types.
Categories:
Pro
ACF Relationship Select Filter in Bricks

ACF Relationship Select Filter in Bricks

In the BricksLabs Facebook group, a user asks: I'm learning about ACF relationships and attempting to output a list of posts on any given page,…
Categories:
Pro
“Truncate text to these many characters” Bricks Control

“Truncate text to these many characters” Bricks Control

Bricks provides a :<number> dynamic data tag modifier that can be used to limit the amount of text by the specified number of words. Ex.:…