{"id":2271,"date":"2019-06-29T12:23:45","date_gmt":"2019-06-29T11:23:45","guid":{"rendered":"https:\/\/www.nathankowald.com\/blog\/?p=2271"},"modified":"2022-03-08T23:52:44","modified_gmt":"2022-03-08T23:52:44","slug":"wordpress-shortcode-if-elseif-else-statements","status":"publish","type":"post","link":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/","title":{"rendered":"WordPress shortcode: if-elseif-else statements"},"content":{"rendered":"\r\n<p class=\"wp-block-paragraph\">I found a <a href=\"https:\/\/level7systems.co.uk\/wordpress-shortcodes-else-statement\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"great blog post (opens in a new tab)\">great post<\/a> which shows how to easily use an if-else shortcode in WordPress.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">[if is_user_logged_in]\r\n    You are already logged in.\r\n[else]\r\n    Display registration form.\r\n[\/if]<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A <a href=\"https:\/\/www.php.net\/manual\/en\/language.types.callable.php\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"PHP callable (opens in a new tab)\">callable<\/a> must be used in the [if] condition.<\/p>\r\n<p>In the above example, <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/is_user_logged_in\/\" target=\"_blank\" rel=\"nofollow noopener\">is_user_logged_in<\/a> is the callable. This is a built in WordPress function to check whether the current visitor is a logged in user. It&#8217;s a shortcode equivalent of this PHP code:<\/p>\r\n<pre class=\"wp-block-preformatted\">&lt;?php<br \/>if ( is_user_logged_in() ) {\r\n    echo \"You are already logged in.\";\r\n} else {\r\n    echo \"Display registration form.\";\r\n}\r\n<\/pre>\r\n<p>The callable you use will likely be the name of a WordPress function, or function added by a plugin. It can also be an <span class=\"type\">object<\/span> method or a static class method.<br \/><br \/>Callables support parameters, just like functions.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">[if is_singular book]\r\n    Show related books\r\n[\/if]\r\n<\/pre>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">What if you need to check more than one condition?<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">I needed to check <em>two<\/em> conditions:<br \/>1. Is user a &#8220;Member&#8221;<br \/>2. Is user logged in to WordPress<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>I needed support for if-elseif-else statements.<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">If a user was a <em>member<\/em>\u00a0I needed to show, &#8220;You are already a member&#8221;.<br \/>If a <em>user<\/em> was logged in, I needed to show a signup form. <br \/>Otherwise, I needed to show a <em>different<\/em>\u00a0signup form.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">I modified the code in the article above and found a solution for doing if-elseif-else conditions.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">I changed the code to return a string (error message) instead of an Exception. A thrown Exception will not allow you to access the WordPress editor, if a non-callable is used in the shortcode. We need access to the editor to resolve this.<\/p>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\">Install the plugin<\/h4>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Clone <a href=\"https:\/\/github.com\/n8kowald\/if-elseif-else-shortcode\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"this repo (opens in a new tab)\">the repo<\/a> to your <strong>\/wp-content\/plugins\/<\/strong> folder and the activate the plugin.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">git clone https:\/\/github.com\/n8kowald\/if-elseif-else-shortcode<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">This allows you to use the following shortcode:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">[if is_admin]\r\n    Hi God, you're up late\r\n[elseif is_user_logged_in]\r\n    Hi Zero Cool, welcome back\r\n[else]\r\n    Welcome to the website. Please register to continue.\r\n[\/if]<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">We can use multiple <strong>elseif<\/strong> statements for an unlimited amount of conditions.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">[if is_admin]\r\n    Hi Mr The Plague.\r\n[elseif is_user_logged_in]\r\n    Hi Zero Cool, hack the planet!\r\n[elseif is_single]\r\n   Pool on the roof must have a leak.\r\n[else]\r\n    Welcome an0n. Please look around but don't steal my fries.\r\n[\/if]<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">You can use <strong>if<\/strong> on its own<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">[if is_admin]\r\n    Hi Mr The Plague.\r\n[\/if]<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">You can use <strong>if-else<\/strong> without the <strong>elseif<\/strong><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">[if is_admin]\r\n    Hi Mr The Plague.\r\n[else]\r\n    Welcome an0n. Please look around but don't steal my fries.\r\n[\/if]<\/pre>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Allowed callables<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The following callable functions are allowed by default:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">comments_open<br \/>get_field\r\nis_404\r\nis_admin\r\nis_archive\r\nis_author\r\nis_category\r\nis_day\r\nis_feed\r\nis_front_page\r\nis_home\r\nis_month\r\nis_page\r\nis_search\r\nis_single\r\nis_singular\r\nis_sticky\r\nis_super_admin\r\nis_tag\r\nis_tax\r\nis_time\r\nis_user_logged_in\r\nis_year\r\npings_open<\/pre>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Adding callables<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">To allow other callables you must use the <strong>if_elseif_else_shortcode_allowed_callables<\/strong> filter.<br \/><br \/>This &#8220;allow other functions&#8221; filter should be added to <a href=\"https:\/\/kinsta.com\/blog\/wordpress-hooks\/#where-to-register-hooks-and-their-functions\" target=\"_blank\" rel=\"nofollow noopener\">wherever you put your hooks<\/a>. That could be in:<\/p>\r\n<ul>\r\n<li>a custom plugin: <strong>wp-content\/plugins\/plugin\/plugin.php<\/strong><\/li>\r\n<li>a child theme&#8217;s functions.php: <strong>wp-content\/themes\/theme-child\/functions.php<\/strong><\/li>\r\n<li>or a theme&#8217;s functions.php: <strong>wp-content\/themes\/theme\/functions.php<\/strong><\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">&lt;?php\r\nadd_filter( 'if_elseif_else_shortcode_allowed_callables', function( $whitelist ) {\r\n    $whitelist[] = 'your_callable_here';\r\n \u00a0\u00a0\r\n    return $whitelist;\r\n}); <\/pre>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Supported callable types<\/h3>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Function names: <strong>is_user_logged_in<\/strong><\/li>\r\n<li>Static\u00a0class\u00a0method\u00a0calls\u00a0(&gt;=PHP\u00a05.2.3): <strong>MyClass::myCallbackMethod<\/strong><\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">[if is_user_logged_in]\r\n    Hello user\r\n[elseif User::is_member_logged_in]\r\n    Hello member\r\n[else]\r\n    Hello, please log in\r\n[\/if]<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> in the above example, you would need to add <strong>User::is_member_logged_in<\/strong> to the allowed callables list.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Passing parameters to callables<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Parameters are passed as space separated strings<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">[if is_singular books]\r\n \u00a0 \u00a0Related books here.\r\n[\/if] <\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">If your callable accepts multiple parameters<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">&lt;?php\r\nfunction is_garfield( $animal, $colour ) {\r\n    return $animal === 'cat' &amp;&amp; $colour === 'orange';\r\n}<\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">[if is_garfield cat orange]\r\n \u00a0 \u00a0 Yes, this is garfield.\r\n[\/if]<\/pre>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Testing<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">If you want to simplify the main function or fix a bug, the <a href=\"https:\/\/github.com\/n8kowald\/if-elseif-else-shortcode\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"created a plugin (opens in a new tab)\">plugin<\/a> includes WordPress tests for refactored code.<\/p>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\">Install PHPUnit and PHPUnit Polyfills<\/h4>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">composer install<\/pre>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\">Install the WordPress testing library and database<\/h4>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Run this from the plugin directory. <br \/>Replace <strong>mysql_username<\/strong> and <strong>mysql_password<\/strong> with your MySQL username and password:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">.\/bin\/install-wp-tests.sh wordpress_tests mysql_username mysql_password<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">You can then run tests with:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">vendor\/bin\/phpunit<\/pre>\r\n","protected":false},"excerpt":{"rendered":"<p>I found a great post which shows how to easily use an if-else shortcode in WordPress. [if is_user_logged_in] You are already logged in. [else] Display registration form. [\/if] A callable must be used in the [if] condition. In the above example, is_user_logged_in is the callable. This is a built in WordPress function to check whether [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[7,33],"tags":[],"class_list":["post-2271","post","type-post","status-publish","format-standard","hentry","category-web-development","category-wordpress"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"I found a great post which shows how to easily use an if-else shortcode in WordPress. [if is_user_logged_in] You are already logged in. [else] Display registration form. [\/if] A callable must be used in the [if] condition. In the above example, is_user_logged_in is the callable. This is a built in WordPress function to check whether\" \/>\n\t<meta name=\"robots\" content=\"noarchive, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"Nathan Kowald\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Nathan&#039;s Blog | Web development and useful information\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"WordPress shortcode: if-elseif-else statements \u2014 Nathan&#039;s Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"I found a great post which shows how to easily use an if-else shortcode in WordPress. [if is_user_logged_in] You are already logged in. [else] Display registration form. [\/if] A callable must be used in the [if] condition. In the above example, is_user_logged_in is the callable. This is a built in WordPress function to check whether\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-06-29T11:23:45+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2022-03-08T23:52:44+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"WordPress shortcode: if-elseif-else statements \u2014 Nathan&#039;s Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"I found a great post which shows how to easily use an if-else shortcode in WordPress. [if is_user_logged_in] You are already logged in. [else] Display registration form. [\/if] A callable must be used in the [if] condition. In the above example, is_user_logged_in is the callable. This is a built in WordPress function to check whether\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2019\\\/06\\\/wordpress-shortcode-if-elseif-else-statements\\\/#article\",\"name\":\"WordPress shortcode: if-elseif-else statements \\u2014 Nathan's Blog\",\"headline\":\"WordPress shortcode: if-elseif-else statements\",\"author\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/author\\\/ozymandias\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2019\\\/06\\\/wordpress-shortcode-if-elseif-else-statements\\\/#articleImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/854acd146177108a75d95bc5fe67d244ccd1cd444eb62abe806923d3113f4319?s=96&d=mm&r=pg\",\"width\":96,\"height\":96,\"caption\":\"Nathan Kowald\"},\"datePublished\":\"2019-06-29T12:23:45+09:30\",\"dateModified\":\"2022-03-08T23:52:44+10:30\",\"inLanguage\":\"en-US\",\"commentCount\":6,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2019\\\/06\\\/wordpress-shortcode-if-elseif-else-statements\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2019\\\/06\\\/wordpress-shortcode-if-elseif-else-statements\\\/#webpage\"},\"articleSection\":\"Web Development, WordPress\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2019\\\/06\\\/wordpress-shortcode-if-elseif-else-statements\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/#listItem\",\"name\":\"Web Development\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/#listItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/wordpress\\\/#listItem\",\"name\":\"WordPress\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/wordpress\\\/#listItem\",\"position\":3,\"name\":\"WordPress\",\"item\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/wordpress\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2019\\\/06\\\/wordpress-shortcode-if-elseif-else-statements\\\/#listItem\",\"name\":\"WordPress shortcode: if-elseif-else statements\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/#listItem\",\"name\":\"Web Development\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2019\\\/06\\\/wordpress-shortcode-if-elseif-else-statements\\\/#listItem\",\"position\":4,\"name\":\"WordPress shortcode: if-elseif-else statements\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/wordpress\\\/#listItem\",\"name\":\"WordPress\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/#person\",\"name\":\"Nathan Kowald\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2019\\\/06\\\/wordpress-shortcode-if-elseif-else-statements\\\/#personImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/854acd146177108a75d95bc5fe67d244ccd1cd444eb62abe806923d3113f4319?s=96&d=mm&r=pg\",\"width\":96,\"height\":96,\"caption\":\"Nathan Kowald\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/author\\\/ozymandias\\\/#author\",\"url\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/author\\\/ozymandias\\\/\",\"name\":\"Nathan Kowald\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2019\\\/06\\\/wordpress-shortcode-if-elseif-else-statements\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/854acd146177108a75d95bc5fe67d244ccd1cd444eb62abe806923d3113f4319?s=96&d=mm&r=pg\",\"width\":96,\"height\":96,\"caption\":\"Nathan Kowald\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2019\\\/06\\\/wordpress-shortcode-if-elseif-else-statements\\\/#webpage\",\"url\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2019\\\/06\\\/wordpress-shortcode-if-elseif-else-statements\\\/\",\"name\":\"WordPress shortcode: if-elseif-else statements \\u2014 Nathan's Blog\",\"description\":\"I found a great post which shows how to easily use an if-else shortcode in WordPress. [if is_user_logged_in] You are already logged in. [else] Display registration form. [\\\/if] A callable must be used in the [if] condition. In the above example, is_user_logged_in is the callable. This is a built in WordPress function to check whether\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2019\\\/06\\\/wordpress-shortcode-if-elseif-else-statements\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/author\\\/ozymandias\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/author\\\/ozymandias\\\/#author\"},\"datePublished\":\"2019-06-29T12:23:45+09:30\",\"dateModified\":\"2022-03-08T23:52:44+10:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/\",\"name\":\"Nathan's Blog\",\"description\":\"Web development and useful information\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"WordPress shortcode: if-elseif-else statements \u2014 Nathan's Blog","description":"I found a great post which shows how to easily use an if-else shortcode in WordPress. [if is_user_logged_in] You are already logged in. [else] Display registration form. [\/if] A callable must be used in the [if] condition. In the above example, is_user_logged_in is the callable. This is a built in WordPress function to check whether","canonical_url":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/","robots":"noarchive, max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/#article","name":"WordPress shortcode: if-elseif-else statements \u2014 Nathan's Blog","headline":"WordPress shortcode: if-elseif-else statements","author":{"@id":"https:\/\/www.nathankowald.com\/blog\/author\/ozymandias\/#author"},"publisher":{"@id":"https:\/\/www.nathankowald.com\/blog\/#person"},"image":{"@type":"ImageObject","@id":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/#articleImage","url":"https:\/\/secure.gravatar.com\/avatar\/854acd146177108a75d95bc5fe67d244ccd1cd444eb62abe806923d3113f4319?s=96&d=mm&r=pg","width":96,"height":96,"caption":"Nathan Kowald"},"datePublished":"2019-06-29T12:23:45+09:30","dateModified":"2022-03-08T23:52:44+10:30","inLanguage":"en-US","commentCount":6,"mainEntityOfPage":{"@id":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/#webpage"},"isPartOf":{"@id":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/#webpage"},"articleSection":"Web Development, WordPress"},{"@type":"BreadcrumbList","@id":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.nathankowald.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/#listItem","name":"Web Development"}},{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/#listItem","position":2,"name":"Web Development","item":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/wordpress\/#listItem","name":"WordPress"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/wordpress\/#listItem","position":3,"name":"WordPress","item":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/wordpress\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/#listItem","name":"WordPress shortcode: if-elseif-else statements"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/#listItem","name":"Web Development"}},{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/#listItem","position":4,"name":"WordPress shortcode: if-elseif-else statements","previousItem":{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/wordpress\/#listItem","name":"WordPress"}}]},{"@type":"Person","@id":"https:\/\/www.nathankowald.com\/blog\/#person","name":"Nathan Kowald","image":{"@type":"ImageObject","@id":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/#personImage","url":"https:\/\/secure.gravatar.com\/avatar\/854acd146177108a75d95bc5fe67d244ccd1cd444eb62abe806923d3113f4319?s=96&d=mm&r=pg","width":96,"height":96,"caption":"Nathan Kowald"}},{"@type":"Person","@id":"https:\/\/www.nathankowald.com\/blog\/author\/ozymandias\/#author","url":"https:\/\/www.nathankowald.com\/blog\/author\/ozymandias\/","name":"Nathan Kowald","image":{"@type":"ImageObject","@id":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/854acd146177108a75d95bc5fe67d244ccd1cd444eb62abe806923d3113f4319?s=96&d=mm&r=pg","width":96,"height":96,"caption":"Nathan Kowald"}},{"@type":"WebPage","@id":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/#webpage","url":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/","name":"WordPress shortcode: if-elseif-else statements \u2014 Nathan's Blog","description":"I found a great post which shows how to easily use an if-else shortcode in WordPress. [if is_user_logged_in] You are already logged in. [else] Display registration form. [\/if] A callable must be used in the [if] condition. In the above example, is_user_logged_in is the callable. This is a built in WordPress function to check whether","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.nathankowald.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/#breadcrumblist"},"author":{"@id":"https:\/\/www.nathankowald.com\/blog\/author\/ozymandias\/#author"},"creator":{"@id":"https:\/\/www.nathankowald.com\/blog\/author\/ozymandias\/#author"},"datePublished":"2019-06-29T12:23:45+09:30","dateModified":"2022-03-08T23:52:44+10:30"},{"@type":"WebSite","@id":"https:\/\/www.nathankowald.com\/blog\/#website","url":"https:\/\/www.nathankowald.com\/blog\/","name":"Nathan's Blog","description":"Web development and useful information","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.nathankowald.com\/blog\/#person"}}]},"og:locale":"en_US","og:site_name":"Nathan's Blog | Web development and useful information","og:type":"article","og:title":"WordPress shortcode: if-elseif-else statements \u2014 Nathan's Blog","og:description":"I found a great post which shows how to easily use an if-else shortcode in WordPress. [if is_user_logged_in] You are already logged in. [else] Display registration form. [\/if] A callable must be used in the [if] condition. In the above example, is_user_logged_in is the callable. This is a built in WordPress function to check whether","og:url":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/","article:published_time":"2019-06-29T11:23:45+00:00","article:modified_time":"2022-03-08T23:52:44+00:00","twitter:card":"summary","twitter:title":"WordPress shortcode: if-elseif-else statements \u2014 Nathan's Blog","twitter:description":"I found a great post which shows how to easily use an if-else shortcode in WordPress. [if is_user_logged_in] You are already logged in. [else] Display registration form. [\/if] A callable must be used in the [if] condition. In the above example, is_user_logged_in is the callable. This is a built in WordPress function to check whether"},"aioseo_meta_data":{"post_id":"2271","title":null,"description":null,"keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[],"defaultGraph":"Article","defaultPostTypeGraph":""},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2020-12-20 21:50:51","updated":"2025-09-13 06:13:17","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.nathankowald.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/\" title=\"Web Development\">Web Development<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/wordpress\/\" title=\"WordPress\">WordPress<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tWordPress shortcode: if-elseif-else statements\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.nathankowald.com\/blog"},{"label":"Web Development","link":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/"},{"label":"WordPress","link":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/wordpress\/"},{"label":"WordPress shortcode: if-elseif-else statements","link":"https:\/\/www.nathankowald.com\/blog\/2019\/06\/wordpress-shortcode-if-elseif-else-statements\/"}],"_links":{"self":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/2271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/comments?post=2271"}],"version-history":[{"count":64,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/2271\/revisions"}],"predecessor-version":[{"id":2838,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/2271\/revisions\/2838"}],"wp:attachment":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/media?parent=2271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/categories?post=2271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/tags?post=2271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}