WordPress Integration
Integrate Toggly feature flags with WordPress using
toggly/wordpress (depends on
core toggly/feature-management-php).
Full SDK-oriented reference: WordPress (PHP SDK). Printable summary: WordPress cheat sheet.
Installation
composer require toggly/wordpress, then ensure the package is available aswp-content/plugins/toggly/(bootstrap filetoggly.php)- Run
composer installin that directory if dependencies are not already installed - Activate Toggly Feature Management under Plugins
- Configure Settings → Toggly (App Key, Environment, optional Base URL and signed definitions)
Usage in themes
<?php if (toggly_is_enabled('new-homepage')): ?>
<?php get_template_part('homepage', 'new'); ?>
<?php else: ?>
<?php get_template_part('homepage', 'legacy'); ?>
<?php endif; ?>
Optional evaluation context:
<?php if (toggly_is_enabled('premium-content', ['userId' => (string) get_current_user_id()])): ?>
<div class="premium-content"><!-- … --></div>
<?php endif; ?>
Shortcode
[toggly_feature name="new-banner"]
<!-- shown when the feature is enabled -->
[/toggly_feature]
Optional JSON context: [toggly_feature name="premium" context='{"userId":"123"}']…[/toggly_feature].
Programmatic checks
$plugin = \Toggly\WordPress\TogglyPlugin::getInstance();
if ($plugin->isEnabled('checkout-v2')) {
// …
}
Hooks and cron
- Actions:
toggly_feature_turns_on,toggly_feature_turns_off - WP-Cron:
toggly_refresh_features(every 5 minutes),toggly_send_stats(every minute; usage stats and metrics)
Admin bar and frontend script
Logged-in administrators get a Toggly admin-bar menu with status for the first few feature keys. With an App Key set, the plugin also enqueues the Toggly UI script from the CDN for the front end.
Next Steps
Abandoned monorepo folder
Toggly.FeatureManagement/Toggly.FeatureManagement.Wordpress/ is an unrelated abandoned demo. Use the PHP package plugin above.