15th Aug '22
/
7 comments

Seasonal banner display in Bricks

Seasonal banner display in Bricks

This Pro tutorial shows how a banner Section can be conditionally output only during/between the start and end dates set in ACF Options page in Bricks.

Update on 17 Aug 2022: Meta Box-specific changes are also provided.

Step 0 - Set timezone

Go to Settings → General and select the city in which the website business operates from for the Timezone.

If this is not set, the times will be GMT-based (universal time instead of local time).

Step 1 - Create ACF Options page

Install and activate ACF Pro.

Add this code in child theme's functions.php or a code snippets plugin:

/** * Create ACF Options page * @link https://www.advancedcustomfields.com/resources/options-page/ */ if ( function_exists( 'acf_add_options_page' ) ) { acf_add_options_page(); }

Step 2 - Set up the fields

Create a new field group called say, "Banner" having these 3 fields:

  • Banner Text - Wysiwyg Editor
  • Banner Start Date - Date Time Picker (or Date Picker)
  • Banner End Date - Date Time Picker (or Date Picker)

The Display and Return formats can be any.

Screenshot from my test site

Location rule: Options Page = Options.

Step 3 - Populate the fields

Click on Options in the admin menu and populate the fields.

Step 4 - Add the banner in Header

Edit your Header template with Bricks.

Add a Section above your actual header containing logo and nav menu. You may want to change its label to Banner.

Add a Basic Text element inside the Section's Container.

Set its text to:

{acf_banner_text}<br>Hurry! Offer available only between {acf_banner_start_date} and {acf_banner_end_date}

Make design changes as needed.

Step 5 - bricks/element/render filter

Add this code in child theme's functions.php or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 630 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
City-based and Country-based Conditional Output in Bricks

City-based and Country-based Conditional Output in Bricks

This Pro tutorial provides the steps to render a Bricks element only if the visitor is from the specified country or city. Note: Caching may…
Categories:
Pro
Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Rendering query-loop enabled posts depending on the value of each post's custom field value is tricky because by default, the custom field plugins' functions or…
Categories:
How to conditionally load your scripts based on an ACF field

How to conditionally load your scripts based on an ACF field

This tutorial provides the PHP codes that can be pasted in order to enqueue your scripts conditionally based on the value of an ACF field…
Categories:
Conditionally Outputting Based on Query Count in Bricks

Conditionally Outputting Based on Query Count in Bricks

Update on 22 Sep 2023: There's a much simpler built-in method now. See this post. In the Bricks Facebook group a user asks: Is there…
Categories:
Pro
Conditional Rendering Based On Meta Box Group’s Sub Field

Conditional Rendering Based On Meta Box Group’s Sub Field

This Pro tutorial shows how we can output an element on a single post pages only if a specified sub-field (custom field created using Meta…
Pro
Dynamic Date in Bricks Countdown Element

Dynamic Date in Bricks Countdown Element

As of Bricks 1.9.7.1, the built-in Countdown element's Date control does not support dynamic data. That is, it is not possible to set this date…
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
Check If The Latest Post Was Published in The Last X Minutes

Check If The Latest Post Was Published in The Last X Minutes

In this Pro tutorial we shall define a custom function that takes in the number of minutes as an argument and returns true if there…
Categories: