WordPress Integration
Use toggly/wordpress to
switch theme content with feature flags. The package includes the PHP core SDK.
Install and initialize
Follow the complete WordPress host setup:
install through Composer, expose toggly.php under wp-content/plugins/toggly,
and load the root autoloader in an MU plugin. Register the two cron intervals
and select snapshot storage before activation. Configure Settings → Toggly
and explicitly refresh before the first evaluation when no usable snapshot
exists. The guide's no-snapshot recipe requires refresh on each new request.
Theme template
After plugin initialization and refresh:
<?php if (toggly_is_enabled('new-homepage')): ?>
<?php get_template_part('homepage', 'new'); ?>
<?php else: ?>
<?php get_template_part('homepage', 'legacy'); ?>
<?php endif; ?>
For user targeting, derive context from the authenticated WordPress user:
$user = wp_get_current_user();
$context = ['identity' => $user->exists() ? (string) $user->ID : null];
$enabled = toggly_is_enabled('premium-content', $context);
Configure the same identity in your Targeting rule. The telemetry identifier is not automatic evaluation context, and a flag does not replace capability checks.
Shortcodes
[toggly_feature name="new-banner"]
<p>Shown when enabled.</p>
[/toggly_feature]
An optional JSON context is literal author-provided data, not authenticated
viewer identity. Use a server-side helper for logged-in user decisions.
Refresh and telemetry
The operational actions are toggly_refresh_features and toggly_send_stats.
Register host cron intervals before plugin initialization and verify events
with wp cron event list. Cron executes in another process, so request-local
telemetry still needs its owning process's shutdown flush. See
the lifecycle guide.