The Location control allows you to conditionally show or hide content based on where the block is located on your website and the attributes of its location. For example, you could limit block visibility based on a post’s categories and tags. Or you could display specific content depending on the author of the post.
This control was built with Full Site Editing in mind. If you are using a block-based theme that supports the upcoming Site Editor, you will be able to unlock the true potential of the Location control. Similarly you can dynamically control widgets in the new block-based widget editor screen available in WordPress 5.8+.
There are many applications for the Referral Source control. Here are a few examples to get you started.
- Display unique calls to action or advertisements depending on a post’s category with the Post Taxonomy rule.
- Assume your theme registers a sidebar widget area. Using the block-based Widget screen, display a related posts block on all posts but hide the block on other post types with the Post Type rule.
- In the Site Editor or within a Query block, display a default featured image if the post does not have one set with the Featured Image attribute rule.
- Using the Site Editor, display different navigation blocks depending on the current page of your website with the Post rule. For example you could hide your main navigation on the checkout page of your online store.
- Using the Site Editor and the Archive rule, dynamically display a call to action in an archive template depending on a specific taxonomy. Say you have a post category called “Tutorials”. On the “Tutorials” archive page create a banner to promotes your video tutorials on YouTube.
How to Enable
Click on any block in the Block Editor and navigate to the Visibility panel in the Settings Sidebar. You will notice a vertical ellipsis icon in the Controls Toolbar. See the screenshot below. Click on the ellipsis and all available visibility controls will appear. Select “Location” and the Location control panel will be added to the selected block.
How to Configure
Instructions are always better with examples. Let’s configure the block to be visible if the current post has category “Tutorials” AND the post was written by “Nick Diego”.
The Location control uses rules and rule sets to determine if the block should be visible. A thorough overview of each available rule is provided below.
Steps to Complete
- Navigate the Location control settings in the Visibility panel.
- Select “Post Taxonomy” from the rules selector.
- Choose “Category” from the taxonomy selector.
- Select “Is at least one of the selected” from the condition selector.
- Choose “Tutorials” from the terms selector.
- Click on the “Add rule” button to add a second rule.
- Choose “Author” from the rules selector.
- Select “Is any of the selected” from the condition selector.
- Choose “Nick Diego” from the authors selector.
The resulting configuration should resemble the screenshot below.
Terminology & Notes
When working with the Location control, you will see many references to the term “post”, particularly in the rules detailed below. This can be confusing, so we want to clearly detail the terminology here. In short, “post” generally refers to any page, post, or custom post type on your site. Third-party plugins often add their own custom post types. For example, WooCommerce adds the products custom post type.
Missing Taxonomy Terms
Many of the location rules allow you to select specific post type taxonomies, such as categories and tags. When the Block Editor loads, all post taxonomies will be available in the Location control. However, if you add a new taxonomy term to the post from within the Block Editor, this new term will not be visible in the Location control until you have refreshed the page. Future versions will address this known bug.
How to Disable
If you would like to disable the Location control at the block level, simply click on the vertical ellipsis icon in the “Controls” toolbar and deselect it. The control can also be disabled globally in the plugin’s Visibility Control Settings.
Note that if this control is disabled globally, any blocks that are actively being hidden by the Location control will become visible again.
Rules & Rule Sets
Similar to other controls in Block Visibility and Block Visibility Pro, the Location control is powered by rules and rule sets. All rules within a rule set must be satisfied for the selected block to be visible. However, you can also create multiple rule sets. Only one rule set needs to apply for the block to be visible.
Within a rule set, you are creating AND conditions between multiple rules. Between two rule sets, you are creating OR conditions.
There are instances when rule errors can occur. For example, if rule inputs are not completely filled out, or if the rule is based on a product that has since been deleted from your store. In these situations, the plugin defaults to showing the block unless other rules apply which would hide the block.
The Type category currently only has one rule. In the future expect more options that pertain to Full Site Editing such as rules based on templates and template parts.
The Page Type rule should not to be confused with the Post Type rule detailed below. This rule allows you to conditionally display block content based on a set of conditionals that define how the current page is used and/or what it is.
The available conditions are:
- Front Page (Homepage) – The page set in the WordPress admin Reading Settings.
- Posts Page (Blog page) – The page set in the WordPress admin Reading Settings.
- Singlular Page – Is the current page a single post?
- Archive Page – Is the current page an archive?
- Search Page – Is the current page a search results page?
- 404 Page – Is the current page a 404 page?
The following rules pertain to post types, taxonomies and individual posts. As a reminder, posts here refers to native posts, pages and any custom post types on your website.
This rule lets you conditionally display block content based on the post type of the current post. This rule shines when used in conjunction with page templates and template parts in the Site Editor.
This rule lets you conditionally display block content based the taxonomy terms of the current post. First choose the taxonomy and then include or exclude individual taxonomy terms. For example, if you would use this rule if you only wanted to show a block if the current post had a specific category.
If you are trying to display blocks only on taxonomy archives, use the Archive Type rule detailed below.
This rule lets you conditionally display block content on specific posts. You first choose the post type and then include or exclude individual posts.
This rule lets you conditionally display block content based on the ID of the current post. You can also set multiple IDs.
Attribute rules enable conditional block visibility based on a variety of post attributes. Does the post have comments? Is there a featured image set? Who is the post author? Is the post hierarchical and does it have child posts? The list goes on… Let your creativity run wild!
Display blocks based on the author of the current post.
This rule lets you conditionally display block content based on the existence or specific number of user comments. The current options are: Post has comments, Post has no comments, and Comment count.
Display blocks based on whether the current post has a featured image or not. This rule is very useful in Query blocks and page templates. Imagine the situation where you need to display a default image if there is no featured image set.
This rule lets you display content based on the hierarchy of the current post. The current options are: Top level page (no parent), Parent page (has children), and Child Page (has parent). This rule pairs nicely with page templates. There are many situations where you may want to display specific blocks on child pages versus parent pages.
This rule lets you display content based on what the current post type supports. The current options are: Comments, Excerpts, and Featured Images. This is a very handy rule to use in post templates or Query blocks.
The Location control currently contains two rules for configuring archive-based conditional visibility. You will need to be using the Site Editor or the block-based Widget Screen to get the most out of these controls. Without the Site Editor or Widget Screen, it’s near impossible to position block content on archive pages. All the more reason to upgrade to a block-based theme. ????
This rule allows you to conditionally display block content on archive pages based on the archive type. Type includes the post types and taxonomies as well as author and date archives.
This rule provide more control than the Archive Type control detailed above. It lets conditionally display block content on archives based on individual taxonomy terms and specific authors.
Hide When Rules Apply
By default, the block will be visible if the applied rules are satisfied. Simply toggle the “Hide when rules apply” setting to hide the block instead.