Aleš Sýkora / January 5, 2024 / 0 comments

Display Bricks element if is_page or is_archive or is_single

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.

Using the reusable template part within Bricks builder.

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

  1. Add the archive_title
  2. Set the conditions to the Dynamic data and echo:is_archive is true

Display post title on pages and posts in Bricks

  1. Add the post_title
  2. Set the conditions to the Dynamic data and echo:is_post is true and if you need to use it also on pages, add secondary conditional with echo:is_page is true

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:

  1. is_home(): Checks if the main blog page is being displayed.
  2. is_front_page(): Checks if a static front page or the main blog page is being displayed.
  3. is_single(): Checks if a single post is being displayed.
  4. is_singular(): Checks if any single post, page, or attachment is being displayed.
  5. is_page(): Checks if a page is being displayed.
  6. is_attachment(): Checks if an attachment page is being displayed.
  7. is_category(): Checks if a category page is being displayed.
  8. is_tag(): Checks if a tag page is being displayed.
  9. is_tax(): Checks if any taxonomy page is being displayed.
  10. is_archive(): Checks if any type of archive page is being displayed (e.g., category, tag, date-based archives, etc.).
  11. is_post_type_archive(): Checks if an archive page for a custom post type is being displayed.
  12. is_author(): Checks if an author page is being displayed.
  13. is_search(): Checks if search results are being displayed.
  14. is_404(): Checks if a 404 error page is being displayed.
  15. is_date(): Checks if any date-based archive page is being displayed (e.g., year, month, day archives).
  16. is_year(): Checks if a yearly archive page is being displayed.
  17. is_month(): Checks if a monthly archive page is being displayed.
  18. is_day(): Checks if a daily archive page is being displayed.
  19. is_time(): Checks if a time-based archive page is being displayed.
  20. 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. 🍻

0 comments

Share Your Thoughts