Browsing Tag

conditional shortcode

WordPress Plugins, WordPress Tips

How to show/hide content on specific pages?

April 20, 2018

WordPress provides Conditional Tags to control how a content is displayed on template files base on specific conditions. However, when we need to do this on dynamic content, we cannot use original Conditional Tags PHP code. Don’t worry, WP Conditional Shortcodes plugin will help you to accomplish this.

Download and Install

You can install and active WP Conditional Shortcodes directly in WP Admin Dashboard, or download the plugin package from here.

How to use it?

As you know, WordPress has many conditional tags, but this plugin only supports some basic conditionals tags which comes in shortcode format. Every shortcodes would includes its contents if the condition is true.

Here’s the list of supported shortcodes matches with its conditional.

  • is_single – if showing a single post. Use the optional parameter “ids” to specify specific posts.
  • is_singular – if showing a single post or page.
  • is_page – if showing a page. Use the optional parameter “ids” to specify specific pages.
  • is_home – if showing the blog home.
  • is_front_page – if showing the front page of the site.
  • is_sticky – if the current post or page is ‘sticky’.
  • is_category – if showing a category-based archive. Use the optional parameter “ids” to specify specific categories.
  • is_page – if showing a page.
  • is_tag – if showing a tag-based archive.
  • is_tax – if showing a tag- or category-based archive.
  • is_author – if showing an author-based archive.
  • is_archive – if showing any archive.
  • is_year – if showing a yearly archive.
  • is_month – if showing a monthly archive.
  • is_day – if showing a daily archive.
  • is_time – if showing an hourly or shorter archive.
  • is_feed – if generating a feed.
  • is_search – if showing search results.
  • comments_open – if comments are open for the current post or page.

Especially, with  is_page, is_category and is_single shortcodes, you also can use ids=”” attribute to list of the ids that you want to apply the condition.

For example :

[is_page ids="76, 339"]hello[/is_page]

[is_category ids="5, 7"]hello[/is_page]

[is_single ids="94, 63"]hello[/is_single]

In the reverse, you can use prefix not_ before the shortcode name to negative the condition and use it as a if else condition with the positive condition.

[is_single]
This is only shown if showing just this post.
[not_single]
This is shown everywhere else.
[/is_single]