A shortcode to display content based on context.
Author: | Hassan Derakhshandeh (profile at wordpress.org) |
WordPress version required: | 3.1 |
WordPress version tested: | 5.4.1 |
Plugin version: | 0.2 |
Added to WordPress repository: | 28-01-2015 |
Last updated: | 26-05-2020
Warning! This plugin has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.
|
Rating, %: | 100 |
Rated by: | 2 |
Plugin URI: | |
Total downloads: | 3 239 |
Active installs: | 200+ |
Click to start download |
With this shortcode you can take control of where the content is displayed.
Usage
You can use all the conditional tags WordPress provides. Checkout examples below.
Show text only on the homepage:
[if is_front_page] The text [/if]
Show text only on the About page of the site:
[if is_page=”about”] The text [/if]
Show only on the category archive view:
[if is_category] The text [/if]
You can add “not_” before the conditional tag to reverse the logic, example:
Show on all pages of the site except the homepage:
[if not_is_front_page] The text [/if]
OR
Using multiple parameters, the content is displayed when either of the conditions are met (“OR” comparison), for example, show text on both category and tag archive pages:
[if is_category is_tag] The text [/if]
AND
To set multiple conditions you can nest the shortcode, for example show text only on homepage AND if the user is logged in:
[if is_user_logged_in][if is_front_page] The text [/if][/if]
Show a link to wordpress.org site, only on single post pages and only on mobile devices:
[if wp_is_mobile][if is_single] WordPress [/if][/if]
has_term_{taxonomy}
You can use this to check if the current post in the loops belongs to a custom term in the desired taxonomy. See: https://codex.wordpress.org/Function_Reference/has_term
Example, check if current post has the “jazz” term in the “genre” taxonomy:
[if has_term_genre=”jazz”] The text [/if]