23rd Mar '23
/
0 comments

Weekday Condition in Bricks

As of Bricks 1.7, the built-in “Weekday” condition does not work correctly.

Wrong output where it is Thursday on the given day when this was tested

This is most likely due to it not taking the site’s timezone (set in WordPress settings) into account.

To work around this, let’s define a custom function and use it with the Dynamic data condition.

Add the following in child theme‘s functions.php (w/o the opening PHP tag) or a code snippets plugin:

// Function to check if today is the specified (three letter format) weekday.
// Sample usage: bl_is_weekday( 'Thu' )
function bl_is_weekday( $weekday ) {
	$today = wp_date( 'D' );

	return $today === $weekday;
}

and whitelist it.

Ex.:

<?php 

add_filter( 'bricks/code/echo_function_names', function() {
  return [
    'bl_is_weekday'
  ];
} );

You should also add any other functions (native or custom) being used in your Bricks instance in addition to bl_is_weekday. This can be checked at Bricks → Settings → Custom code by clicking the Code review button.

More info on whitelisting can be found here.

and apply it like this:

{echo:bl_is_weekday(Thu)}

Replace Thu with the three-letter week you want to check against.

To output the element when it is NOT the specified weekday, check against 0 instead of 1.

Alternatively, you could simply do:

{echo:wp_date(D)}

to render the element on the specified weekday.

This way, you don’t have to register a custom function.

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Leave the first comment

 

Related Tutorials..

Pro
Media File Attachment Data in Bricks

Media File Attachment Data in Bricks

With a 'Media' query loop, this tutorial shows how we can retrieve various attachment-specific properties inside of the loop.
Categories:
How to apply a custom query var to multiple query loops in Bricks

How to apply a custom query var to multiple query loops in Bricks

In this tutorial, we'll learn how to apply a PHP filter to modify the query var of multiple query loops in a single function Introduction…
Categories:
Conditional Output based on Manual Excerpt in Bricks

Conditional Output based on Manual Excerpt in Bricks

How to display a post’s excerpt only if it has been manually set.
Categories:
Checking for Post Type in Bricks

Checking for Post Type in Bricks

A way to output elements conditionally based on the current post type in the loop in Bricks.
Categories:
Pro
“Pro” Category Ribbon for Posts in Bricks

“Pro” Category Ribbon for Posts in Bricks

This Pro tutorial provides the steps to show a "Pro" ribbon for posts that are categorized under the "Pro" category when using Bricks builder. Step…
Categories:
Pro
Host Post’s Term in Bricks Query Loop

Host Post’s Term in Bricks Query Loop

Updated on 4 Mar 2025 In the BricksLabs Facebook group a user asked: Hi everyone, I’m facing a tricky situation that might have a simple…
Categories:
Pro
Day of Week Condition in Bricks

Day of Week Condition in Bricks

Displaying elements conditionally based on the current day of the week.
Categories: