{"id":10607,"date":"2026-05-17T17:30:38","date_gmt":"2026-05-17T09:30:38","guid":{"rendered":"https:\/\/aeosub.com\/renderwhen\/"},"modified":"2026-05-17T17:30:38","modified_gmt":"2026-05-17T09:30:38","slug":"renderwhen","status":"publish","type":"post","link":"https:\/\/aeosub.com\/zh\/renderwhen\/","title":{"rendered":"RenderWhen for Blocks"},"content":{"rendered":"<div class=\"post-img\" style=\"margin-bottom: 25px\"><img decoding=\"async\" src=\"https:\/\/ps.w.org\/renderwhen\/assets\/banner-1544x500.png?rev=3534394\" alt=\"RenderWhen for Blocks\" style=\"width: 100%;height: auto;border-radius: 12px\"><\/div>\n<div class=\"plugin-info-card\" style=\"border: 1px solid #e2e8f0;border-radius: 10px;overflow: hidden;margin-bottom: 30px;font-family: -apple-system, system-ui, sans-serif;background: #fff\">\n<table style=\"width: 100%;border-collapse: collapse;font-size: 14px\">\n<tr style=\"border-bottom: 1px solid #edf2f7\">\n<th style=\"padding: 15px 20px;text-align: left;width: 35%;color: #4a5568;background: #fcfcfc\"><img decoding=\"async\" src=\"https:\/\/ps.w.org\/renderwhen\/assets\/icon-256x256.png?rev=3534394\" style=\"width: 40px;height: 40px;border-radius: 6px;margin-right: 12px;vertical-align: middle\"> Developer<\/th>\n<td style=\"padding: 15px 20px;font-weight: 500\"><a href=\"https:\/\/profiles.wordpress.org\/abhishekfdd\/\" target=\"_blank\" rel=\"noopener\">Abhishek Kumar<\/a><\/td>\n<\/tr>\n<tr style=\"border-bottom: 1px solid #edf2f7\">\n<th style=\"padding: 12px 20px;text-align: left;color: #4a5568;background: #fcfcfc\">Version<\/th>\n<td style=\"padding: 12px 20px\">v1.0.0<\/td>\n<\/tr>\n<tr style=\"border-bottom: 1px solid #edf2f7\">\n<th style=\"padding: 12px 20px;text-align: left;color: #4a5568;background: #fcfcfc\">Active Installs<\/th>\n<td style=\"padding: 12px 20px\">0 +<\/td>\n<\/tr>\n<tr style=\"border-bottom: 1px solid #edf2f7\">\n<th style=\"padding: 12px 20px;text-align: left;color: #4a5568;background: #fcfcfc\">Requires \/ Tested<\/th>\n<td style=\"padding: 12px 20px\">6.5 \/ 6.9.4<\/td>\n<\/tr>\n<tr style=\"border-bottom: 1px solid #edf2f7\">\n<th style=\"padding: 12px 20px;text-align: left;color: #4a5568;background: #fcfcfc\">Last Updated<\/th>\n<td style=\"padding: 12px 20px\">2026-05-17 9:08am GMT<\/td>\n<\/tr>\n<tr>\n<th style=\"padding: 12px 20px;text-align: left;color: #4a5568;background: #fcfcfc\">Official Link<\/th>\n<td style=\"padding: 12px 20px\"><a href=\"https:\/\/wordpress.org\/plugins\/renderwhen\/\" target=\"_blank\" style=\"text-decoration: none;color: #4a3bca;font-weight: bold\" rel=\"noopener\">View Details \u2192<\/a><\/td>\n<\/tr>\n<\/table><\/div>\n<div class=\"plugin-short-desc\" style=\"margin: 20px 0;padding: 12px 15px;background: #f9fafb;border-left: 4px solid #4a3bca;border-radius: 6px;font-style: italic;color: #4a5568\">Show or hide any block when conditions match. Developer-first API and true server-side rendering \u2014 hidden blocks never reach the browser.<\/div>\n<p>RenderWhen for Blocks adds conditional visibility to every block in the WordPress block editor. Decide who sees what, and when, with a panel that reads exactly how you&#8217;d say it out loud:<\/p>\n<blockquote>\n<p><em>Show this block when the user is logged in.<\/em><br \/>\n  <em>Show this block when the date is between March 1 and March 31.<\/em><br \/>\n  <em>Show this block when the device is mobile.<\/em><\/p>\n<\/blockquote>\n<p>RenderWhen is built around two ideas that set it apart from other visibility plugins:<\/p>\n<ul>\n<li><strong>Server-side rendering only.<\/strong> When a block is hidden by a condition, it is not rendered into the page output at all. No CSS <code>display: none<\/code>, no DOM bloat, no leaked content in view-source. Search engines, screen readers, and your page weight all benefit.<\/li>\n<li><strong>Public Conditions API.<\/strong> The three built-in conditions are registered through the same public API your plugin or theme can use to add your own. No hacks, no internal-only code paths.<\/li>\n<\/ul>\n<p>In the editor, a subtle dashed border marks every block that carries a visibility rule, so a rule-bearing block never disappears from the published page as a surprise. A &#8220;Preview as audience&#8221; sidebar lets you simulate a logged-out visitor, a specific role, or a different device class right in the editor \u2014 blocks whose rule would hide them fade out with a clear badge, no save-and-reload cycle required.<\/p>\n<h4>Built-in conditions (v1.0)<\/h4>\n<ul>\n<li><strong>User state<\/strong> \u2014 show to logged-in users, logged-out users, or specific roles<\/li>\n<li><strong>Date range<\/strong> \u2014 show between two datetimes, timezone-aware<\/li>\n<li><strong>Device type<\/strong> \u2014 show on desktop, tablet, or mobile<\/li>\n<\/ul>\n<h4>Designed for<\/h4>\n<ul>\n<li>Agencies and freelancers building client sites who want a clean, predictable visibility tool<\/li>\n<li>Developers who need an extension point, not another walled garden<\/li>\n<li>Anyone who cares about page weight and SEO hygiene<\/li>\n<\/ul>\n<h4>What this plugin deliberately does NOT do<\/h4>\n<p>It does one thing well rather than ten things adequately. Out of scope in v1.0:<\/p>\n<ul>\n<li>Multi-condition AND\/OR groups (planned for v1.1)<\/li>\n<li>URL \/ cookie \/ referrer \/ geolocation conditions<\/li>\n<li>WooCommerce, ACF, or membership integrations<\/li>\n<li>A settings dashboard<\/li>\n<\/ul>\n<p>If you need those today, <a href=\"https:\/\/wordpress.org\/plugins\/conditional-blocks\/\" rel=\"ugc noopener\" target=\"_blank\">Conditional Blocks<\/a> and <a href=\"https:\/\/wordpress.org\/plugins\/block-visibility\/\" rel=\"ugc noopener\" target=\"_blank\">Block Visibility<\/a> are excellent and well-established choices.<\/p>\n<h4>For developers<\/h4>\n<p>Register a custom condition in three steps. Implement the interface, add it to the registry, ship.<\/p>\n<pre><code>add_action( 'renderwhen_register_conditions', function ( $registry ) {\n    $registry-&gt;register( new My_Plugin\\Conditions\\Country_Condition() );\n} );\n<\/code><\/pre>\n<p>Your condition class implements <code>RenderWhenConditionsInterface_Condition<\/code>:<\/p>\n<pre><code>namespace My_PluginConditions;\n\nuse RenderWhenConditionsInterface_Condition;\n\nclass Country_Condition implements Interface_Condition {\n    public function get_id(): string {\n        return 'country';\n    }\n\n    public function get_label(): string {\n        return __( 'Visitor country', 'my-plugin' );\n    }\n\n    public function get_schema(): array {\n        return array(\n            'type'       =&gt; 'object',\n            'properties' =&gt; array(\n                'countries' =&gt; array(\n                    'type'  =&gt; 'array',\n                    'items' =&gt; array( 'type' =&gt; 'string' ),\n                ),\n            ),\n        );\n    }\n\n    public function evaluate( array $settings, array $context ): bool {\n        $current = my_plugin_detect_country();\n        return in_array( $current, $settings['countries'] ?? array(), true );\n    }\n}\n<\/code><\/pre>\n<p>The full set of public filters:<\/p>\n<ul>\n<li><code>renderwhen_register_conditions<\/code> \u2014 register your conditions here<\/li>\n<li><code>renderwhen_evaluate_{condition_id}<\/code> \u2014 last-mile override of any condition&#8217;s result<\/li>\n<li><code>renderwhen_render_block_hidden<\/code> \u2014 fires when a block is hidden, useful for cache busters and SEO tools<\/li>\n<li><code>renderwhen_device_type<\/code> \u2014 swap in your own device detection<\/li>\n<\/ul>\n<p>The plugin is developed openly on GitHub. Issues, PRs, and architecture discussions welcome: https:\/\/github.com\/abhishekfdd\/renderwhen<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Show or hide any block when conditions match. Developer-first API and true server-side rendering \u2014 hidden blocks never reach the browser.<\/p>","protected":false},"author":1,"featured_media":9317,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[252],"tags":[793,638,1054,641,1055,555],"class_list":["post-10607","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-trends","tag-block-editor","tag-blocks","tag-conditional","tag-gutenberg","tag-visibility","tag-wordpress-plugin"],"_links":{"self":[{"href":"https:\/\/aeosub.com\/zh\/wp-json\/wp\/v2\/posts\/10607","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aeosub.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aeosub.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aeosub.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aeosub.com\/zh\/wp-json\/wp\/v2\/comments?post=10607"}],"version-history":[{"count":0,"href":"https:\/\/aeosub.com\/zh\/wp-json\/wp\/v2\/posts\/10607\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aeosub.com\/zh\/wp-json\/wp\/v2\/media\/9317"}],"wp:attachment":[{"href":"https:\/\/aeosub.com\/zh\/wp-json\/wp\/v2\/media?parent=10607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aeosub.com\/zh\/wp-json\/wp\/v2\/categories?post=10607"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aeosub.com\/zh\/wp-json\/wp\/v2\/tags?post=10607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}