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

4 comments

Leave your comment

 

Related Tutorials..

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
How to Inject a Different Type of Post in Bricks Query Loop

How to Inject a Different Type of Post in Bricks Query Loop

Updated on 26 Aug 2024 A user asks: Hello, I'd like to inject a CPT post card inside of a Bricks query loop of a different CPT…
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:
Pro
How to programmatically add a class to an element in Bricks

How to programmatically add a class to an element in Bricks

This Pro tutorial shows how a dynamic class can be added to a query loop element in Bricks programmatically. Let's take an example where posts…
Pro
Filtering a Bricks Terms query on Term archive pages

Filtering a Bricks Terms query on Term archive pages

On product category archives, how to show product type names but only those that the current product category has.