Replies: 1
I am using pro version of this plugin. For some third-party content, I use shortcode [cookie_after_acceptcategory=”…”] to show this content only after cookies of the specific category are accepted by the user.
If the cookies of this category are not allowed, the content of the shortcode will not show up – the plugin does it’s job. However, I want to show a message to users that this is happening (and may be have them changing their cookie settings).
I could not find a shortcode like [cookie_not_accepted].
My approach was to add my own shortcode to function.php and check if the plugin’s [cookie_after_accept] shortcode would do something to content. If not, cookies seem to be accepted. If it removes content, cookies are probably not allowed.
I did not find time to dig into do_shortcode_tag (since WP 4.7) yet, but this would also require to check if the result of [cookie_after_accept] is positive or negative.
For future versions, I would suggest a shortcode to show content if cookies are not accepted.
My solutions for now (functions.php):
function cookie_not_accepted_shortcode($atts = [], $content = '') {
$atts=shortcode_atts( array(
'category' =>'',
'condition'=>'and'
), $atts );
// build atts into testing shortcode
$att_string = '';
foreach ($atts as $key=>$val) {
$att_string .= ' '. $key .'="'. $val .'"';
}
if (do_shortcode('[cookie_after_accept'. $att_string .']any content[/cookie_after_accept]') != 'any content') {
// content was modified by [cookie_after_accept], wich currently only happens when the content is not allowed due to cookie settings
return $content;
} else {
// cookie settings ok, ignore alternative content of [cookie_not_accepted] shortcode
return '';
}
}
add_shortcode('cookie_not_accepted','cookie_not_accepted_shortcode');