Updated: 27/01/2023

Published: 20/01/2023

By Peter K

How to create a blog schema in Bricks Builder

Introduction to dynamic data

Bricks builder has a dynamic data feature which can then be customised into different schemas.

To do this we need to create a custom function to get some variables that are not available by default.

These variables are:

  • Modified date in format Year-month-day
  • Created date in the format  Year-month-day
  • Category Names without anchor links
  • Featured image url
  • Author URL

 

Edit function.php file

In your bricks child theme, add the following code in your function.php file

  • Append the code at the bottom of the existing code.
function gdv_schema($gdvs)
{
	
	if ($gdvs == "modified-date") {
    return get_the_modified_date('Y-m-d', $post->ID);
	}
	
	if ($gdvs == "created-date") {
    return get_the_date('Y-m-d', $post->ID);
	}
	
	if ($gdvs == "category-names") {
    
	$category_detail=get_the_category($post->ID);//$post->ID
	//return count($category_detail);	
	$li = '';
	$i = 1;	
		foreach($category_detail as $cd){
			
			
			if (count($category_detail) ==  $i) 
			{
			  $li .= $cd->cat_name;
			}else{
				$li .= $cd->cat_name .", ";
			}

			
			$i++;
		}
	return $li;			
		
		
	}
	
	if ($gdvs == "featured-image") {
    return get_the_post_thumbnail_url( $post->ID, 'medium' );
		
	}	

	if ($gdvs == "author-url") {
		
	$author_id  = get_post_field( 'post_author', $post->ID );
    return get_author_posts_url( $author_id ) ;
		
	}
	
}

Edit the posts template

Add the following code in your post templates so it appears on all your posts.

  • Create a Basic Text block and paste the code in there
  • NOTE: The code will not execute if you put it Page Settings > Custom Code (at least in the templates)

See the Pen
Bricks – Blog Schema
by microbite-websites (@microbite-websites)
on CodePen.

Create different types of Schemas

As you can see you can create dynamic schemas to load on your WordPress website.

A great resource for the schema structure is Merkle

Test the Schema

Visit Rich Results Test

Google has an online Schema Tester.

  1. Enter the url of the page you want to test and click Test URL