{"id":8231,"date":"2024-08-01T16:38:40","date_gmt":"2024-08-01T06:38:40","guid":{"rendered":"https:\/\/brickslabs.com\/?p=8231"},"modified":"2025-07-19T10:59:56","modified_gmt":"2025-07-19T00:59:56","slug":"condition-for-checking-bricks-content","status":"publish","type":"post","link":"https:\/\/brickslabs.com\/condition-for-checking-bricks-content\/","title":{"rendered":"Condition for checking Bricks content"},"content":{"rendered":"<div class=\"mp_wrapper\">\n  <div class=\"mepr-unauthorized-excerpt\">\n    <p>In the comments section of <a href=\"https:\/\/brickslabs.com\/the-perfect-bricks-page-template\/\" target=\"_blank\" rel=\"noreferrer noopener\">The Perfect Bricks Page Template<\/a> tutorial, a user asks:<\/p>\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Could this be modified so that instead of has_blocks it used something like has_bricks? I'd like to take the structure that you have (Gutenberg Content section followed by Bricks div) and have it render the Gutenberg content only if the page isn't built with Bricks and use the Bricks div only if the page IS built with Bricks.It's a small distinction, but it's because I often will build a page with Bricks and put the WPcontent element in the layout somewhere. When I do, I won't want the first section (Gutenberg) to display because then there would be duplication.Currently I use a similar setup where the two sections display based on a Metabox switch on each page. I'd prefer to not have to toggle that switch because it often gets forgotten.<\/p>\n<\/blockquote>\n<p>This <a href=\"https:\/\/brickslabs.com\/pro-tutorial\" target=\"_blank\" rel=\"noreferrer noopener\">Pro tutorial<\/a> provides the steps to define a custom function that returns true or false depending on whether the current post (typically, a Page) has <a href=\"https:\/\/brickslabs.com\/go\/bricks\" target=\"_blank\" rel=\"noreferrer noopener\">Bricks<\/a> content and using the function with a dynamic data Bricks condition to output Bricks content when a Page is built with Bricks or WordPress content when there is no Bricks content.<\/p>\n<h2 class=\"wp-block-heading\">Step 1<\/h2>\n<p>Add the following in <a href=\"https:\/\/brickslabs.com\/go\/child-theme\">child theme<\/a>'s <code>functions.php<\/code> (w\/o the opening PHP tag) or a <a href=\"https:\/\/brickslabs.com\/go\/code-snippets-plugin\">code snippets plugin<\/a>:<\/p>\n  <\/div>\n  <div class=\"mepr-unauthorized-message\">\n    <p>This is a BricksLabs Pro tutorial.<\/p>\n<p>For full access login below or create your <a href=\"https:\/\/brickslabs.com\/pro\/\">BricksLabs Pro account<\/a><\/p>\n  <\/div>\n  <div class=\"mepr-login-form-wrap\">\n            \n<div class=\"mp_wrapper mp_login_form\">\n                  <!-- mp-login-form-start -->     <form name=\"mepr_loginform\" id=\"mepr_loginform\" class=\"mepr-form\" action=\"https:\/\/brickslabs.com\/login\/\" method=\"post\">\n            <div class=\"mp-form-row mepr_username\">\n        <div class=\"mp-form-label\">\n                              <label for=\"user_login\">Username<\/label>\n        <\/div>\n        <input type=\"text\" name=\"log\" id=\"user_login\" value=\"\" \/>\n      <\/div>\n      <div class=\"mp-form-row mepr_password\">\n        <div class=\"mp-form-label\">\n          <label for=\"user_pass\">Password<\/label>\n          <div class=\"mp-hide-pw\">\n            <input type=\"password\" name=\"pwd\" id=\"user_pass\" value=\"\" \/>\n            <button type=\"button\" class=\"button mp-hide-pw hide-if-no-js\" data-toggle=\"0\" aria-label=\"Show password\">\n              <span class=\"dashicons dashicons-visibility\" aria-hidden=\"true\"><\/span>\n            <\/button>\n          <\/div>\n        <\/div>\n      <\/div>\n            <div>\n        <label><input name=\"rememberme\" type=\"checkbox\" id=\"rememberme\" value=\"forever\" \/> Remember Me<\/label>\n      <\/div>\n      <div class=\"mp-spacer\">&nbsp;<\/div>\n      <div class=\"submit\">\n        <input type=\"submit\" name=\"wp-submit\" id=\"wp-submit\" class=\"button-primary mepr-share-button \" value=\"Log In\" \/>\n        <input type=\"hidden\" name=\"redirect_to\" value=\"\/wp-json\/wp\/v2\/posts\/8231\" \/>\n        <input type=\"hidden\" name=\"mepr_process_login_form\" value=\"true\" \/>\n        <input type=\"hidden\" name=\"mepr_is_login_page\" value=\"false\" \/>\n      <\/div>\n    <\/form>\n    <div class=\"mp-spacer\">&nbsp;<\/div>\n    <div class=\"mepr-login-actions\">\n        <a\n          href=\"https:\/\/brickslabs.com\/login\/?action=forgot_password\"\n          title=\"Click here to reset your password\"\n        >\n          Forgot Password        <\/a>\n    <\/div>\n\n      \n    <!-- mp-login-form-end --> \n  <\/div>\n      <\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Only outputting <a  class=\"btl_autolink_hyperlink\"  href=\"https:\/\/brickslabs.com\/go\/bricks\"   >Bricks<\/a> content when a Page is built with Bricks, otherwise display WP content.<\/p>\n","protected":false},"author":1,"featured_media":8235,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[5,9],"tags":[55,243],"topic":[267],"class_list":["post-8231","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bricks","category-pro","tag-setup","tag-templating","topic-conditions"],"acf":[],"featured_image_src":"https:\/\/brickslabs.com\/wp-content\/uploads\/2024\/08\/condition-for-checking-bricks-content-600x400.png","featured_image_src_square":"https:\/\/brickslabs.com\/wp-content\/uploads\/2024\/08\/condition-for-checking-bricks-content-600x400.png","author_info":{"display_name":"Sridhar Katakam","author_link":"https:\/\/brickslabs.com\/author\/sridhar\/"},"_links":{"self":[{"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/posts\/8231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/comments?post=8231"}],"version-history":[{"count":0,"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/posts\/8231\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/media\/8235"}],"wp:attachment":[{"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/media?parent=8231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/categories?post=8231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/tags?post=8231"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/topic?post=8231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}