Primary

Shortcodes

The plugin provides the [widgets_control] shortcode which is used to restrict content sections similar to how widgets are shown conditionally. This shortcode is always used to embed a section of content, i.e. you will place the opening and the closing tag around your content section.

Here’s an example:

Widgets Control Shortcode

This is how the entry above would look like on an archive page:

Widgets Control Shortcode Example

The shortcode takes two attributes which determine whether the content that it surrounds will be shown or not. Here is an example:

[widgets_control visibility="show" conditions="{archive}"]
This text will only be visible when the content is rendered on archive pages.
[/widgets_control]

As you can see, the visibility attribute determines whether the conditions are used to show or hide the content section and the conditions attribute allows to indicate tokens similar to how we use them in widgets and sidebars. You can either use visibility="show" or visibility="show not", meaning that the conditions will apply to show the content in the first case or to hide the content in the latter. Actually you can omit visibility="show" completely because that’s the default. Here is another example:

[widgets_control conditions="{category:Fruit} {tag:banana}"]
This text will only be visible when the content is rendered on the "Fruit" category page or on the page for the tag "banana".
[/widgets_control]

Please note that the tokens that can be used in the conditions attribute will be written with curly brackets. For example, {archive} and not [archive] as used in the conditions for widgets and sidebars. This is due to limitations of the expression engine in WordPress that recognises shortcodes in your text.

The following tokens can be used in the conditions attribute to identify certain pages or sets of pages. You can indicate one or more tokens separated by spaces.

  • {id:(ID of a page)} – Identifies a page by its ID. For example, {id:123}.
  • {title:(title of a page)} – Identifies a page by its title. For example, {title:Hello World}.
  • {slug:(slug of a page)} – Identifies a page by its slug. For example, {slug:example-page}.
  • {single} – For single posts.
  • {page} – Identifies pages (the Page post type).
  • {home} – The home page.
  • {front} – The front page.
  • {type:xyz} – For a specific post type.
  • {archive} – Any archive page.
  • {archive:xyz} – The xyz archive page.
  • {category} – Category pages in general.
  • {category:xyz} – A specific category.
  • {has_term:term:taxonomy} – Whether the current post has the taxonomy term.
  • {tag} – A tag archive page.
  • {tag:xyz} – A specific tag archive page.
  • {tax} – A taxonomy archive page.
  • {tax:taxonomy} – A specific taxonomy archive page.
  • {tax:taxonomy:term} – A specific taxonomy term page.
  • {role:xyz} - A specific user role. For example, {role:editor}.
  • {group:xyz} - A specific group. For example, {group:Registered} for any registered user or {group:Premium} for users in a Premium group.
  • {author} – An author page.
  • {author:xyz} – A specific author’s page.
  • {language:xyz} - A specific language.
  • {search} – The search results page.
  • {404} – A 404 Not Found page
  • !... – Prefix tokens, slugs or titles with ! to exclude matching pages*.

*Tokens can be prefixed with an exclamation mark ! to exclude pages that match the condition. For example, one could show the content on any pages except a specific page.