Add cookie consent

hey there,
I’d like to add my cookie notice just before the head tag

<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />

thanks for your help

Hi There,

Please set up a child theme first: https://theme.co/apex/forum/t/setup-how-to-setup-child-themes/57.

After that adding the following code under functions.php file locates in your child theme:

add_action( 'wp_head', 'x_insert_header_scripts' );
function x_insert_header_scripts(){
	?>
	<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />
	<?php
}

Hope it helps :slight_smile:

1 Like

How would I change the stylesheet of the banner to my own. right now its using an external one //cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css

thanks for your help!

Hi There,

Download that CSS file and then upload a copy on your child theme root folder. Then we have to update the code suggested previously to reference on the new file like below:

add_action( 'wp_enqueue_scripts', 'child_enqueue_styles');

function child_enqueue_styles() {

wp_enqueue_style( 'cookie-style', get_stylesheet_directory_uri() . '/cookieconsent.min.css', array());
}

See the following guide:
https://codex.wordpress.org/Function_Reference/get_template_directory
https://developer.wordpress.org/reference/functions/wp_enqueue_style/

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.