WordPress plugin intelligence profile

If Shortcode

This plugin provides an [if] shortcode to conditionally render content.

WP PlugIndex snapshot

Current directory snapshot

Tested up to WordPress 6.6
Current version0.3.0
WordPress coverageTested up to WordPress 6.6
Minimum stackWP 3.0.1 · PHP 5.4
Directory statusactive
Last directory update2 Aug 20242y ago
Active installations200Adoption metric — not a quality score
WordPress.org rating5.0 / 5 from 6 ratings
Official packageDirect from WordPress.org

Repository metrics are context, not quality scores. Active installations measure adoption and can strongly reflect a plugin’s age and historical popularity. Ratings, recent updates and “Tested up to” metadata also do not guarantee modern code, error-free operation, security, feature completeness or suitability for a particular site. Why active installs don’t tell the whole story →

WP PlugIndex currently records If Shortcode version 0.3.0 as active, updated 2y ago and tested up to WordPress 6.6.

Overview

About this plugin

This plugin provides an [if] shortcode to conditionally render content. The syntax is the following:

[if condition1 condition2=false condition3]{content}[/if]

Conditions are passed as attribute names. Multiple conditions evaluate to the result of ORing all of them. In other words, if at least one condition evaluates to the desired boolean result, {content} is rendered, otherwise it is discarded.

Attribute values determine if we want the condition to be true or false. A value of '0', 'false', '' (the empty string), 'null' or 'no' means we expect the condition to be false. Anything else, including the absense of a value, is interpreted as true.

For example, suppose that we want to include a sentence in a post, but only for anonymous visitors:

[/if]

It also provides an [else] shortcode and an [eitherway] one for use inside [if] blocks. [else] will render its content if the condition evaluates to false, and [eitherway] will render its content regardless of the evaluation result.

When used outside an [if] block, these shortcodes behave as if the whole content is surrounded by an [if] shortcode whose condition evaluates to true. In other words, an [else] shortcode would not render any content, while a [eitherway] one would. You can use as many of these shortcodes as you like in a single [if] block, which gives you the ability to do things like:

  • Am I logged in?

[if is_user_logged_in]- Yes you are. [else]- No you are not. [/else][eitherway]- I'm sorry, what?

[/eitherway]- I said YOU A-R-E LOGGED IN!!! [else]- YOU ARE NOT LOGGED IN!!! [/else][/if]

A multitude of conditions are supported out-of-the-box. The following evaluate to the result of the corresponding WordPress Conditional Tag, using the no-parameter syntax:

is_single is_singular is_page is_home is_front_page is_privacy_policy is_attachment is_category is_tag is_tax is_author is_archive is_year is_month is_date is_day is_time is_feed is_search is_sticky is_preview has_term has_excerpt comments_open pings_open is_404 is_user_logged_in is_super_admin is_multi_author is_multisite is_main_site is_child_theme

For example, the evaluation of the is_page condition is equivalent to calling is_page() with no parameter.

Extending

The functionality of the plugin can be extended by other plugins, by means of adding custom conditions through filters. To add a custom condition, a filter hook must be defined in the following manner:

'my_condition','my_condition_evaluator');

function my_condition_evaluator($value) { $evaluate=.... /* add your evaluation code here */ return $evaluate; }

Then, you can use your custom condition like so:

[if my_condition]{content}[/if]

A big thanks to M Miller for the normalize_empty_atts() function.

WordPress.org metadata

Plugin tags

Topics listed for this plugin in the WordPress.org directory.

  • conditional tags
  • else
  • if
  • shortcode
Compatibility & maintenance

Compatibility & maintenance

Tested up to WordPress 6.6

Not yet marked as tested with WordPress 7.1. WordPress.org currently lists Tested up to 6.6.

Current WordPress releaseWordPress 7.1
WordPress.org Tested up to6.6
Minimum requirementsWordPress 3.0.1 · PHP 5.4
Update activity2 Aug 20242y ago

“Tested up to” is directory metadata supplied by the plugin author. WP PlugIndex does not turn an older declaration into a claim that the plugin is incompatible.

Changes recorded by WP PlugIndex

Recent tracked changes

No tracked version or compatibility changes have been recorded by WP PlugIndex yet.

Tracking & source

WP PlugIndex tracks public WordPress.org directory metadata and records selected version, compatibility and availability changes as they are detected.

Plugin watchlist

Watch this plugin

Sign in to your WP PlugIndex account or create a free account. Free accounts can watch up to 5 plugins and see what changed.

Watch limit

Watchlist limit reached

You have reached your current active watch limit.