The GDPR and similar laws require that consent must be obtained before setting non-essential cookies or processing personal data. WP Consent API helps you meet those requirements.
Different plugins handling consent differently can cause conflicts or inconsistent behavior. The API unifies consent handling across the Wordpress site.
Wordpress plugin developers can use built-in API functions instead of rolling out their own consent logic.
The API allows developers and plugins to:
// Check if consent is given for 'analytics'
if (wp_has_consent('analytics')) {
// Load analytics script
}
granted
denied
unknown
Before loading tools like Google Analytics or Facebook Pixel:
if (wp_has_consent('analytics')) {
// Insert analytics code
}
or In your PHP code:
if (wp_has_consent('marketing')){
//do marketing stuff
}