Key points:
- ACF Blocks lets you control who sees what on your WordPress site using familiar PHP templates instead of JavaScript.
- You can show or hide content based on anything you can imagine: user roles, membership status, custom fields, devices, and more – all without touching complex code.
- You can transform any WordPress block into dynamic content that responds to user behavior, making it easy to build features like member-only content and device-specific layouts.
Sometimes, you need your WordPress site to show different content to different users. Consider scenarios like hiding premium content from free users, showing special offers only to logged-in members, or displaying a simpler version of your site on mobile phones.
Most ways of doing this require complex coding skills, which, let’s face it, is way too complicated for many site owners. But thanks to WordPress tools like ACF Blocks by Advanced Custom Fields (ACF®), you can control what content appears on your site using simple PHP templates.
This guide covers everything you need to know about controlling content on your WordPress site. You’ll learn how to use conditional blocks to show or hide content based on things like user roles, devices, and membership status. Best of all, we’ll focus on solutions that don’t require any coding knowledge.
The limitations of native WordPress conditional content
WordPress has some rudimentary tools for controlling who sees what on your site. Out of the box, you can show or hide content based on screen size, create different layouts for mobile and desktop users, and set up basic visibility rules for different user roles. The block editor even lets you toggle entire blocks on or off, and developers can use template parts to show different content in different situations.
Despite these built-in features, WordPress’s native options aren’t ideal for real-world websites. You can’t create visibility rules based on custom fields, which means, for instance, no country-specific content or membership-level restrictions. There’s also no way to filter content based on user behavior or create anything beyond basic show/hide options.
Plus, if you want to combine multiple conditions – like showing content only to premium members who are using mobile devices – you’ll need to write custom code. WordPress also lacks detailed permission controls and can’t manage content based on user interactions. These gaps are why many site owners search for alternative content management solutions, which we’ll dive into next.
Block Visibility: A no-code approach to conditional content
Block Visibility is a no-code solution that transforms any WordPress block into dynamic content. The plugin works directly in the familiar WordPress block editor, making it incredibly simple to control who sees what content on your site. Here’s how it works:
- Create your content using any WordPress block.
- Select your visibility conditions from the block settings.
- Save your page.
The plugin is also packed with powerful visibility controls. You can schedule content with specific start and end dates, show or hide blocks based on user login status, and control visibility for specific user roles.
It works with WooCommerce, ACF, Easy Digital Downloads, and WP Fusion. This means you can create sophisticated visibility rules based on purchase history, custom fields, download status, and CRM data.
Block Visibility offers a simple solution for site owners, so it has some limitations. Complex visibility rules that require custom PHP will still need a developer’s touch. For example, if you need to show content based on sophisticated combinations of user data and custom fields, ACF Blocks can help.
Powerful conditional content with ACF Blocks
A key feature of ACF PRO, ACF Blocks gives developers a simple way to control content using PHP template files. Instead of complex JavaScript, you can use familiar PHP if/else statements to decide what content shows up on your site. You can control content based on:
- User roles and capabilities.
- Custom field values.
- Dates and time.
- Any WordPress data accessible through PHP.
The system revolves around ACF’s powerful functions like get_field()
and have_rows()
. These functions let you check field values and create complex visibility conditions. For example, you might show content only when specific custom fields have certain values, or display blocks based on user metadata.
ACF Blocks is built entirely on PHP, making it a natural fit for WordPress developers. The template system mirrors traditional WordPress theme development, so there’s no need to learn JavaScript frameworks like React. As you develop, you’ll see your changes instantly in the block editor’s live preview, making it easy to test and refine visibility conditions.
These blocks work perfectly anywhere in WordPress, so you can use them in posts, pages, or other block-enabled areas. You get complete control over HTML output, and your blocks work perfectly with WordPress features like alignment and anchors. You can also use the same block multiple times on a single post, and they’re fully compatible with repeater and gallery fields.
Supercharge Your Website With Premium Features Using ACF PRO
Speed up your workflow and unlock features to better develop websites using ACF Blocks and Options Pages, with the Flexible Content, Repeater, Clone, Gallery Fields & More.
ACF conditional content implementation guide
Here’s what you need to do to display conditional content with ACF Blocks:
- In your (child) theme’s folder, create a folder called Blocks. Inside it, create a folder for your custom block and name it My-custom-block.
- In that folder, add a block.json file and paste the following code into it to register the block:
{
"name": "acf/my-custom-block",
"title": "My Custom Block",
"description": "A custom block built with ACF.",
"renderTemplate": "template.php",
"category": "formatting",
"icon": "admin-comments",
"keywords": ["custom", "acf"]
}
- Go to ACF > Field Group > Add New and create a new field that we’re going to use to toggle the conditional content on or off. You can use a lot of fields depending on what you’re going for, but we’ll use the True / False field type.
- Copy the custom field’s name since we’re going to use it for the next step.
- Next, create a template.php file in the same folder as the block.json and paste the following code into it to define the structure and logic of the block:
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
// Use the custom field name inside the parentheses below
$show = get_field('show_content');
?>
<div>
<button id="toggleBtn"><?php echo $show ? 'Hide' : 'Show'; ?></button>
<div id="content" style="display: <?php echo $show ? 'block' : 'none'; ?>">
<p>Your conditional content will show up here.</p>
</div>
</div>
<script>
document.getElementById('toggleBtn').addEventListener('click', function(){
var content = document.getElementById('content');
content.style.display = (content.style.display === 'none') ? 'block' : 'none';
this.textContent = (content.style.display === 'none') ? 'Show' : 'Hide';
});
</script>
- Add the following code to your (child) theme’s functions.php to register all custom blocks on
init
:
<?php
/**
* Register Custom ACF Blocks on WordPress Init.
*
*/
function mytheme_register_acf_blocks() {
// Register the testimonial block using WordPress's register_block_type() function.
// The block's JSON configuration and template files should be in the specified directory.
register_block_type( __DIR__ . '/blocks/my-custom-block' );
}
// Hook our function to the 'init' action so it runs early in the WordPress load process.
add_action( 'init', 'mytheme_register_acf_blocks' );
- Go back to ACF and edit the field group you created. Under Location Rules, set it to show if Block + is equal to the block you created.
- Create a new post or page from the dashboard, add your block where you want it to appear, and then publish it.
- Test the functionality by viewing the page and clicking the button.
Practical uses of conditional content with ACF Blocks
Now you’re familiar with the basics of ACF Blocks. The custom block’s content appears on the condition that the True / False field is true, but you can build on that to come up with some creative uses of this feature, both on the front and backend.
Here are several practical examples of using different ACF fields to display conditional content across various industries and niches to get you inspired:
- An eCommerce store can use a True / False field to toggle a “Sale active” banner. If the store is running a promotion, the banner appears; otherwise, it remains hidden.
- Hospitality/restaurants can use a Select field for seasonal menus or special event notifications. Based on the current season or event selection (e.g., summer specials or holiday menu), display tailored content like featured dishes or dining packages.
- Real estate sites can use a Number field to manage pricing information. For example, if a property’s price is reduced by a certain percentage, a “Price Reduced” badge is conditionally shown, drawing buyer attention to deals.
- Education sites can use a Radio Button field to switch between course levels or formats. Depending on whether the course is beginner, intermediate, or advanced, show different curriculum details, testimonials, or enrollment prompts.
- Healthcare platforms can use a Checkbox field to display specialized services (e.g., telehealth availability). When checked, additional details, such as how to schedule virtual appointments, are revealed.
- Events pages can use a Date Picker field to conditionally display registration information. If the event date is upcoming, show the registration link and details; if not, display a “Past event” notice.
Upgrade your WordPress development with ACF Blocks
Creating conditional content in WordPress doesn’t have to mean learning complex JavaScript or diving into the block API. While WordPress’s native approach requires JavaScript expertise, ACF Blocks lets you stick with familiar PHP to get the job done.
What makes ACF Blocks special is how it combines field groups with location rules. This means you can create truly dynamic content that knows where it’s being used and who’s viewing it. Want to show different content based on user roles, custom fields, and page location all at once? ACF Blocks handles that easily through PHP templates.
Ready to build more dynamic WordPress sites? ACF PRO includes everything you need to create powerful conditional blocks. You’ll get a complete PHP-based framework that makes block development straightforward, plus all the tools to create exactly the kind of dynamic content your site needs. Get started with ACF now.
For plugin support, please contact our support team directly, as comments aren't actively monitored.