Aleš Sýkora / January 5, 2024 / 0 comments
Display Bricks element if is_page or is_archive or is_single
min read / Bricks Builder, Custom Code, Plugins, WordPress / Share on: Twitter, LinkedIn, Facebook
Post summary: Use global reusable templates and change the content with determitaion functions.
If you need to hide/display elements with conditions, you may want to use conditions like if is page – display page title. If is archive, display archive title.
I use this often, when I have an hero section template and I use it in multiple templates as reusable template part within template block in Bricks. So I have a template for single post, archive etc. but I only use one template for hero section and I am editing it from one place.
How to do that? In this example, I built two rich text elements and add the conditions with dynamic data.
Display archive title on archive pages in Bricks
- Add the
archive_title
- Set the conditions to the Dynamic data and
echo:is_archive
istrue
Display post title on pages and posts in Bricks
- Add the
post_title
- Set the conditions to the Dynamic data and
echo:is_post
istrue
and if you need to use it also on pages, add secondary conditional withecho:is_page
istrue
Which functions can be used to determine the type of content in WordPress?
In WordPress, there are several functions for determining the type of content being displayed. These functions help you identify what type of page or post you’re currently viewing. Each of these functions returns true
or false
depending on whether the current query matches a specific type of content.
Here’s a list of determination functions in WordPress:
is_home()
: Checks if the main blog page is being displayed.is_front_page()
: Checks if a static front page or the main blog page is being displayed.is_single()
: Checks if a single post is being displayed.is_singular()
: Checks if any single post, page, or attachment is being displayed.is_page()
: Checks if a page is being displayed.is_attachment()
: Checks if an attachment page is being displayed.is_category()
: Checks if a category page is being displayed.is_tag()
: Checks if a tag page is being displayed.is_tax()
: Checks if any taxonomy page is being displayed.is_archive()
: Checks if any type of archive page is being displayed (e.g., category, tag, date-based archives, etc.).is_post_type_archive()
: Checks if an archive page for a custom post type is being displayed.is_author()
: Checks if an author page is being displayed.is_search()
: Checks if search results are being displayed.is_404()
: Checks if a 404 error page is being displayed.is_date()
: Checks if any date-based archive page is being displayed (e.g., year, month, day archives).is_year()
: Checks if a yearly archive page is being displayed.is_month()
: Checks if a monthly archive page is being displayed.is_day()
: Checks if a daily archive page is being displayed.is_time()
: Checks if a time-based archive page is being displayed.is_new_day()
: Checks if the current post is published on a new day compared to the previous post.
Each of these functions is useful for determining the context of the page within your Bricks builder WordPress templates and can be used to display different content or templates based on the type of page or post being displayed.
Fuel my passion for writing with a beer🍺
Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻