"Cookie Settings" Link That Reopens the Consent Banner
Adds a [cookie_settings_link] shortcode that lets visitors change their cookie choice at any time: it clears the stored choice and reloads the page so the consent banner shows again.
Opens WPIDE on
Code
add_shortcode( 'cookie_settings_link', function ( $atts ) {
$atts = shortcode_atts( array( 'text' => 'Cookie settings' ), $atts, 'cookie_settings_link' );
return '<button type="button" class="wpide-cookie-settings" onclick="document.cookie=\'wpide_consent=;path=/;max-age=0\';location.reload();" style="background:none;border:0;padding:0;color:inherit;text-decoration:underline;cursor:pointer;font:inherit;">' . esc_html( $atts['text'] ) . '</button>';
} );
Notes
Made for the simple wpide_consent cookie banner; consent plugins usually provide their own settings link.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.