Skip to content

Widget Display

Ben Gillbanks edited this page Dec 6, 2019 · 6 revisions

Use the widget display settings to set when which pages widgets should appear on.

The display settings uses a custom rules box where you can enter a set of rules that define when rules should appear.

  • Each widget can have multiple rules.
  • The order of the rules is irrelevant. The exclusion rules will be checked first. The inclusion rules will be checked after.
  • If an exclusion rule says to hide the widget then the widget will be hidden and nothing else will be checked.
  • If an inclusion rule says to show the widget then the widget will be displayed and nothing else will be checked.
  • If there are no rules the widget will be displayed.
  • When viewing the site in the customizer hidden widgets will be made semi-transparent. This allows you to edit them, and to preview their visibility setting.

Rule format

The rules are structured in the same format as CSS properties. A name, optionally followed by a colon and then comma separated parameters, ending with a semicolon.

If there's a single rule then you don't need the semicolon.

If you want to exclude a property then prefix it with a !.

Rules

  • home Display on the homepage. No parameters.
  • !home Don't display on the homepage. No parameters.
  • single Display on any singular post type. Posts, pages, and any custom post types. The parameters can contain a list of ids to restrict the display to pages with those ids.
  • !single Don't display on singular post type.
  • archive Display on any archive page. Optionally ID's can be supplied as parameters, and these can be used to include and exclude different archive ids.
  • !archive Don't display on archive pages.
  • postType Display on pages with the specified post type. Requires parameters. The parameters should be a list of post types.
  • !postType Don't display on the specified page type.
  • postCategory Display on single posts that are published in the specified categories.
  • !postCategory Don't display on single posts that are published in the specified categories.
  • postTaxonomy Display on single posts (any CPT) that are published in the specified taxonomies. The first parameter should be the term type, the other parameters should be the categories you want to check.
  • !postTaxonomy Don't display on single posts that are published in the specified taxonomies.
  • 404 Display on 404 pages.
  • !404 Don't display on 404 pages.
  • pageChild Display on a page that is the child of the specified id. Includes the page parent. Requires parameters specifying list of parent pages.
  • !pageChild Hide on pages that are children of the specified id.

I am open to adding new rule types. If you have ideas for different rules then create an issue, describing what you want to do, with an example of how or why you would use it and I'll see what I can do.

Examples

  • home Only display on the homepage.
  • home; archive Display on the homepage and archive pages.
  • postType: post Display on single posts and post archives. Not pages.
  • postCategory: 3 Display on single posts that are in category 3.
  • postTaxonomy: tag,12 Display on single posts that are in tag 3.
  • archive:6 Display on the archive with an ID of 6.
  • !single:4; single Display on single posts but exclude post/ page with id 4.
Clone this wiki locally