{"id":44905,"date":"2026-08-19T13:06:37","date_gmt":"2026-08-19T13:06:37","guid":{"rendered":"https:\/\/getshortcodes.com\/?post_type=docs&#038;p=44905"},"modified":"2026-08-19T13:06:37","modified_gmt":"2026-08-19T13:06:37","slug":"conditional","status":"publish","type":"docs","link":"https:\/\/getshortcodes.com\/docs\/conditional\/","title":{"rendered":"Conditional"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>[su_conditional]<\/code> shortcode displays its enclosed content only when a selected condition matches the current visitor or request. Use it for member-only messages, guest calls to action, role-specific instructions, scheduled announcements, device or language targeting, URL-based content, post context, cookies, and WooCommerce customer resources.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"description\">Description<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Conditional is a wrapping shortcode. Select one condition, fill in the fields related to that condition, and place the content you want to control between the opening and closing shortcode tags. Text, HTML, and other shortcodes can be used inside it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The default <code>is<\/code> operator displays the content when the condition matches. Set <code>operator=\"is_not\"<\/code> to reverse the result.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"basic-usage\">Basic usage<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>[su_conditional condition=\"logged_in\"]\n  Welcome back! Here is your private content.\n[\/su_conditional]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"available-conditions\">Available conditions<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><code>logged_in<\/code> \u2014 the visitor is logged in.<\/li><li><code>logged_out<\/code> \u2014 the visitor is not logged in.<\/li><li><code>user_role<\/code> \u2014 the current user has any of the specified WordPress roles.<\/li><li><code>device<\/code> \u2014 WordPress identifies the request as mobile or desktop.<\/li><li><code>language<\/code> \u2014 the current locale matches a full locale or two-letter language code.<\/li><li><code>date<\/code> \u2014 the current date is inside an inclusive date range.<\/li><li><code>time<\/code> \u2014 the current time is inside an inclusive daily time range.<\/li><li><code>datetime<\/code> \u2014 the current date and time is inside an inclusive range.<\/li><li><code>cookie<\/code> \u2014 a named cookie exists and, optionally, has an exact value.<\/li><li><code>url<\/code> \u2014 the current request URL contains the specified text.<\/li><li><code>referrer<\/code> \u2014 the HTTP referrer contains the specified text.<\/li><li><code>post_type<\/code> \u2014 the current post has any of the specified post types.<\/li><li><code>post_category<\/code> \u2014 the current post has any of the specified categories.<\/li><li><code>woocommerce_purchase<\/code> \u2014 the logged-in WooCommerce customer bought any of the specified products.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"parameters\">Parameters<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Parameter<\/th><th>Used with<\/th><th>Description<\/th><th>Values \/ format<\/th><th>Default<\/th><\/tr><\/thead><tbody><tr><td><code>condition<\/code><\/td><td>All<\/td><td>Selects the rule that controls whether the enclosed content is displayed. Fields for other conditions are ignored.<\/td><td><code>logged_in<\/code>, <code>logged_out<\/code>, <code>user_role<\/code>, <code>device<\/code>, <code>language<\/code>, <code>date<\/code>, <code>time<\/code>, <code>datetime<\/code>, <code>cookie<\/code>, <code>url<\/code>, <code>referrer<\/code>, <code>post_type<\/code>, <code>post_category<\/code>, <code>woocommerce_purchase<\/code><\/td><td>Empty<\/td><\/tr><tr><td><code>operator<\/code><\/td><td>All<\/td><td>Controls whether the selected condition is used directly or inverted.<\/td><td><code>is<\/code>, <code>is_not<\/code><\/td><td><code>is<\/code><\/td><\/tr><tr><td><code>role<\/code><\/td><td><code>user_role<\/code><\/td><td>Matches when the logged-in user has any listed role.<\/td><td>One or more role slugs separated by commas, for example <code>administrator,editor<\/code>.<\/td><td>Empty<\/td><\/tr><tr><td><code>device<\/code><\/td><td><code>device<\/code><\/td><td>Selects the server-detected device type.<\/td><td><code>mobile<\/code>, <code>desktop<\/code><\/td><td><code>mobile<\/code><\/td><\/tr><tr><td><code>language<\/code><\/td><td><code>language<\/code><\/td><td>Matches the current WordPress locale.<\/td><td>A locale such as <code>en_US<\/code> or a two-letter language code such as <code>en<\/code>.<\/td><td>Empty<\/td><\/tr><tr><td><code>cookie_name<\/code><\/td><td><code>cookie<\/code><\/td><td>Name of the cookie that must exist.<\/td><td>A valid cookie name.<\/td><td>Empty<\/td><\/tr><tr><td><code>cookie_value<\/code><\/td><td><code>cookie<\/code><\/td><td>Optional exact cookie value. Leave empty to check only whether the cookie exists.<\/td><td>Plain text.<\/td><td>Empty<\/td><\/tr><tr><td><code>product_id<\/code><\/td><td><code>woocommerce_purchase<\/code><\/td><td>Matches when the logged-in customer bought any listed product.<\/td><td>One or more numeric product IDs separated by commas.<\/td><td>Empty<\/td><\/tr><tr><td><code>date_from<\/code><br><code>date_to<\/code><\/td><td><code>date<\/code><\/td><td>Inclusive start and end date. Either boundary can be omitted.<\/td><td><code>YYYY-MM-DD<\/code> in the WordPress site timezone.<\/td><td>Empty<\/td><\/tr><tr><td><code>time_from<\/code><br><code>time_to<\/code><\/td><td><code>time<\/code><\/td><td>Inclusive daily start and end time. A range such as <code>22:00<\/code>\u2013<code>06:00<\/code> crosses midnight. Either boundary can be omitted.<\/td><td><code>HH:MM<\/code> in the WordPress site timezone.<\/td><td>Empty<\/td><\/tr><tr><td><code>datetime_from<\/code><br><code>datetime_to<\/code><\/td><td><code>datetime<\/code><\/td><td>Inclusive start and end date and time. Either boundary can be omitted.<\/td><td><code>YYYY-MM-DD HH:MM<\/code> in the WordPress site timezone.<\/td><td>Empty<\/td><\/tr><tr><td><code>url_contains<\/code><\/td><td><code>url<\/code><\/td><td>Text that must occur in the current request URL.<\/td><td>Plain text or a URL fragment.<\/td><td>Empty<\/td><\/tr><tr><td><code>referrer_contains<\/code><\/td><td><code>referrer<\/code><\/td><td>Text that must occur in the optional HTTP referrer.<\/td><td>Plain text or a URL fragment.<\/td><td>Empty<\/td><\/tr><tr><td><code>post_type<\/code><\/td><td><code>post_type<\/code><\/td><td>Matches when the current post has any listed post type.<\/td><td>One or more post type slugs separated by commas, for example <code>post,page<\/code>.<\/td><td>Empty<\/td><\/tr><tr><td><code>category<\/code><\/td><td><code>post_category<\/code><\/td><td>Matches when the current post has any listed category.<\/td><td>One or more category slugs or numeric IDs separated by commas.<\/td><td>Empty<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"examples\">Examples<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"show-content-to-logged-out-visitors\">Show content to logged-out visitors<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>[su_conditional condition=\"logged_out\"]\n  Create a free account to access this resource.\n[\/su_conditional]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"target-selected-user-roles\">Target selected user roles<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>[su_conditional condition=\"user_role\" role=\"administrator,editor\"]\n  Editorial note: please review this page.\n[\/su_conditional]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"schedule-content-by-date-and-time\">Schedule content by date and time<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>[su_conditional condition=\"datetime\" datetime_from=\"2026-11-27 00:00\" datetime_to=\"2026-11-30 23:59\"]\n  The weekend offer is live.\n[\/su_conditional]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"use-a-time-range-that-crosses-midnight\">Use a time range that crosses midnight<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>[su_conditional condition=\"time\" time_from=\"22:00\" time_to=\"06:00\"]\n  Night support is now available.\n[\/su_conditional]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"match-a-language\">Match a language<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>[su_conditional condition=\"language\" language=\"en\"]\n  Read the English version of this guide.\n[\/su_conditional]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"check-a-cookie-value\">Check a cookie value<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>[su_conditional condition=\"cookie\" cookie_name=\"plan\" cookie_value=\"pro\"]\n  Thanks for being a Pro member.\n[\/su_conditional]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"show-content-on-selected-post-types-or-categories\">Show content on selected post types or categories<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>[su_conditional condition=\"post_type\" post_type=\"post,page\"]\n  This note appears on posts and pages.\n[\/su_conditional]\n\n[su_conditional condition=\"post_category\" category=\"news,42\"]\n  Read the latest category update.\n[\/su_conditional]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"check-a-woocommerce-purchase\">Check a WooCommerce purchase<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>[su_conditional condition=\"woocommerce_purchase\" product_id=\"123,456\"]\n  Download your customer resources.\n[\/su_conditional]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"invert-a-condition\">Invert a condition<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>[su_conditional condition=\"user_role\" operator=\"is_not\" role=\"administrator\"]\n  This notice is shown to users who are not administrators.\n[\/su_conditional]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"important-notes\">Important notes<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Full-page caching:<\/strong> conditions based on users, devices, cookies, or purchases can return the wrong output when a cache or CDN serves the same completed page to different visitors. The shortcode does not disable caching automatically.<\/li><li><strong>Device detection:<\/strong> the <code>device<\/code> condition uses WordPress server-side request detection. It does not react to the browser viewport width and should not replace responsive CSS.<\/li><li><strong>Site timezone:<\/strong> <code>date<\/code>, <code>time<\/code>, and <code>datetime<\/code> conditions use the timezone configured in WordPress, not necessarily the visitor\u2019s local timezone.<\/li><li><strong>HTTP referrer:<\/strong> browsers and privacy tools can omit or shorten referrer data. Do not use it as the only control for important or protected content.<\/li><li><strong>WooCommerce purchases:<\/strong> the visitor must be logged in and WooCommerce must be active for the purchase condition to match.<\/li><li><strong>Access control:<\/strong> Conditional controls rendered page content, but it is not a substitute for authorization checks on protected files, private data, or sensitive actions.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"developer-api\">Developer API<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Developers can register custom condition names with the <code>shortcodes_ultimate_conditional_conditions<\/code> filter and calculate their result with the <code>shortcodes_ultimate_conditional_result<\/code> filter.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_filter(\n  'shortcodes_ultimate_conditional_conditions',\n  function ( $conditions ) {\n    $conditions[] = 'front_page';\n    return $conditions;\n  }\n);\n\nadd_filter(\n  'shortcodes_ultimate_conditional_result',\n  function ( $result, $condition, $atts ) {\n    if ( 'front_page' === $condition ) {\n      return is_front_page();\n    }\n\n    return $result;\n  },\n  10,\n  3\n);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The custom condition can then be used manually:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[su_conditional condition=\"front_page\"]\n  This content appears on the front page.\n[\/su_conditional]<\/code><\/pre>\n","protected":false},"featured_media":0,"template":"","docs_category":[21],"class_list":["post-44905","docs","type-docs","status-publish","hentry","docs_category-shortcodes"],"acf":[],"_links":{"self":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs\/44905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/types\/docs"}],"wp:attachment":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/media?parent=44905"}],"wp:term":[{"taxonomy":"docs_category","embeddable":true,"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs_category?post=44905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}