| 开发者 | metalfreek |
|---|---|
| 更新时间 | 2026年11月14日 21:44 |
| PHP版本: | 7.4 及以上 |
| WordPress版本: | 7.1 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
[yangra_conditional role="editor"]…[yangra_conditional_else]…[/yangra_conditional] shows its content only to matching visitors. Build it with Yangra Conditional → Shortcode builder.
Conditions: user state (logged in or out), user role, page type, archive page and visitor device. Combine them, choose Show or Hide, and use "is" or "is not".
build/ are compiled from the human-readable source in assets/src/, which ships with the plugin, using @wordpress/scripts (npm run build).
The plugin includes the Freemius WordPress SDK (version 2.13.5, GPLv3) in vendor/freemius/wordpress-sdk/, which handles opt-in diagnostics and Pro licensing. Its source is available in that repository.
yangra-conditional folder to /wp-content/plugins/, or install it from the Plugins screen.No. Hiding a menu item only removes the link: the page is still reachable by its URL. A hidden block isn't sent to the browser, but the post it's in is still public. To protect content, use a membership or access-control plugin.
No. Scheduled elements are taken out of the page in the visitor's browser, but they are still in the page source, where search engines can find them, and visitors can change their clock. Use them for promotions and announcements, not for anything secret. Visitors without JavaScript don't see scheduled elements at all.
Most conditions do. User state and role usually work, because caches skip logged-in users; page type and archive page are the same for every visitor of a URL. Visitor device can show the wrong result on a cached page, because the first visitor's version is cached for everyone. Exclude those pages from the cache, or use a cache that keeps a separate copy for mobile. Scheduled elements always work with caching. The plugin never changes how your site is cached, with one exception: scheduled content purges the pages it changes, see below.
It looks up the visitor's IP address in a database stored on your site, so nothing is sent to an outside service and the address is never stored. The data is the "user-country" database from ip-location-db, which is in the public domain (PDDL); it's updated with each plugin release and imported in the background after an update. Country detection is approximate: visitors on a VPN or proxy are matched by its country. Like Visitor device, Visitor location can show the wrong result on a cached page. If your site is behind Cloudflare or another proxy, choose where the address is read from in Yangra Conditional → Settings.
With Polylang active, it uses the language Polylang shows the page in, so it works with page caching. Polylang is the only multilingual plugin supported: with WPML or any other, or with none, it uses the languages the visitor's browser asks for, and matches if any of them matches; like Visitor device, this can show the wrong result on a cached page. A language without a region matches every region: English matches English (United States) and English (United Kingdom).
Yes, with the supported caching plugins: WP Rocket, W3 Total Cache, LiteSpeed Cache, WP Super Cache, WP Fastest Cache and SiteGround Optimizer. At each show and hide time, and when an active item changes, the pages it's shown on are purged from the active one. Host caches and CDNs (such as Cloudflare) aren't purged: clear them by hand, or purge them from your own code with the yangra_conditional_purge_post action. The purges run on WP-Cron, which only runs when WordPress handles a visit, so on a busy cached site they can run late. A real server cron job runs them on time.
Only in the main content of the pages and posts you choose, through the the_content filter: not in archives, excerpts, feeds or the REST API. Page builders that render pages without the_content aren't supported, so check pages built with one while an item is active.
Menus shown with wp_nav_menu() (theme menu locations and the Navigation Menu widget) and the Navigation block. Menus a theme or plugin builds in another way are not covered.
Every menu item, block and widget is shown again, including ones you hid from logged-in users. Conditional shortcodes show as plain text, with both their content and their "else" content. Your rules stay saved.
Yes, up to three levels. WordPress can't put a shortcode inside another with the same name, so use [yangra_conditional_2] inside [yangra_conditional], and [yangra_conditional_3] inside that. Each has its own "else" tag, e.g. [yangra_conditional_2_else].
Rules move with a WordPress export. Rules that use specific items (categories, tags, terms or authors) are saved by ID, and IDs change on import, so check those rules after importing.