{"id":48,"date":"2025-09-26T08:50:54","date_gmt":"2025-09-26T08:50:54","guid":{"rendered":"https:\/\/ska-blocks.com\/docs\/2025\/09\/26\/conditions-block\/"},"modified":"2025-09-26T09:34:06","modified_gmt":"2025-09-26T09:34:06","slug":"conditions-block","status":"publish","type":"post","link":"https:\/\/ska-blocks.com\/docs\/conditions-block\/","title":{"rendered":"Conditions block"},"content":{"rendered":"\n<p class=\"lead\">The Conditions and Condition blocks can be used to render content when a certain condition applies.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Condition<\/h2>\n\n\n\n<p>The <code>ska\/condition<\/code> block allows to set any whitelisted PHP function name as as the condition for rendering itself.<\/p>\n\n\n\n<div role=\"figure\" class=\"wp-block-ska-image image\"><img decoding=\"async\" src=\"https:\/\/ska-blocks.com\/docs\/wp-content\/uploads\/sites\/3\/2024\/03\/image-117.png\" alt=\"Block editor controls for the Condition block\" width=\"271\" height=\"339\" loading=\"lazy\"\/><\/div>\n\n\n\n<p>For example, using the condition <code>get_locale<\/code> and value <code>en_US<\/code> allows to render content only when the current language is English.<\/p>\n\n\n\n<p>Functions can be whitelisted under <strong>ska-blocks -> Theme -> Permissions -> Allowed conditions<\/strong>.<\/p>\n\n\n\n<p>All functions that start with <code>ska_condition_<\/code> are whitelisted automatically, so defining one in the child theme&#8217;s <code>functions.php<\/code> is easiest.<\/p>\n\n\n\n<div class=\"wp-block-ska-code not-prose ska-preset--ska-theme--code\"><div class=\"content\"><pre class=\"code php language-php\"><code class=\"language-php\">function ska_condition_campaign_active() {\n\t$shortcodes = ska_blocks()->get('options')->get('dynamicShortcodes');\n\treturn isset($shortcodes&#91;'campaign-active']) &amp;&amp; !empty($shortcodes&#91;'campaign-active']);\n}<\/code><\/pre><button :class=\"{error: state === &apos;error&apos;, success: state === &apos;success&apos;}\" x-data=\"{state:&apos;&apos;}\" x-on:click=\"navigator.clipboard ? (navigator.clipboard.writeText($el.previousElementSibling.innerText), $el.innerText = `Copied!`, state = &apos;success&apos;) : ($el.innerText = `Can&amp;#039;t copy`, state = &apos;error&apos;)\" class=\"copy\" type=\"button\">Copy<\/button><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conditions<\/h2>\n\n\n\n<p>The <code>ska\/conditions<\/code> block is just a wrapper for <code>ska\/condition<\/code> blocks, that doesn&#8217;t do anything special in the front end, how ever in the block editor it only displays 1 child condition at a time &#8211; first condition or the condition that is currently selected in the List view.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/ska-blocks.com\/docs\/wp-content\/uploads\/sites\/3\/2024\/03\/image-30.png\" alt=\"\" class=\"wp-image-292\"\/><\/figure>\n\n\n\n<p>This can be used to keep the block editor content more compact, how ever it may be confusing for people who don&#8217;t know about this behavior. If you need to disable it, you can add a Tailwind class:<\/p>\n\n\n\n<div class=\"wp-block-ska-code not-prose ska-preset--ska-theme--code\"><div class=\"content\"><pre class=\"code css language-css\"><code class=\"language-css\">editor:&#91;&amp;>.wp-block:not(#\\_):not(#\\_):not(#\\_)]:block!<\/code><\/pre><button :class=\"{error: state === &apos;error&apos;, success: state === &apos;success&apos;}\" x-data=\"{state:&apos;&apos;}\" x-on:click=\"navigator.clipboard ? (navigator.clipboard.writeText($el.previousElementSibling.innerText), $el.innerText = `Copied!`, state = &apos;success&apos;) : ($el.innerText = `Can&amp;#039;t copy`, state = &apos;error&apos;)\" class=\"copy\" type=\"button\">Copy<\/button><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The Conditions and Condition blocks can be used to render content when a certain condition applies. Condition The ska\/condition block allows to set any whitelisted PHP function name as as the condition for rendering itself. For example, using the condition get_locale and value en_US allows to render content only when the current language is English.&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[4],"class_list":["post-48","post","type-post","status-publish","format-standard","hentry","category-ska-theme","tag-blocks"],"_links":{"self":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/comments?post=48"}],"version-history":[{"count":1,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":191,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts\/48\/revisions\/191"}],"wp:attachment":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/media?parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/categories?post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/tags?post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}