Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookieconsent not working in WordPress #613

Closed
Mamunson opened this issue Jan 5, 2024 · 2 comments
Closed

Cookieconsent not working in WordPress #613

Mamunson opened this issue Jan 5, 2024 · 2 comments

Comments

@Mamunson
Copy link

Mamunson commented Jan 5, 2024

Hi there,

Cookieconsent is not working on my WordPress page. This is inside the functions.php file:

`function my_theme_enqueue_scripts()
{
// Enqueue jQuery
wp_enqueue_script('jquery');

// Enqueue external CSS stylesheets
wp_enqueue_style('cookieconsent-stylesheet', 'https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@v2.9.2/dist/cookieconsent.css', array(), '2.9.2', 'all');

wp_enqueue_style('style-css', get_template_directory_uri() . '/style.css', array(), '1.0', 'all');

// Enqueue your custom app.js before cookieconsent-init.js
wp_enqueue_script('app-js', get_template_directory_uri() . '/js/app.js', array('jquery'), '1.0.0', true);

// Enqueue cookieconsent-init.js with dependency on app.js
wp_enqueue_script('cookieconsent-init', get_template_directory_uri() . '/js/cookieconsent-init.js', array('app-js'), '1.0.0', true);

}

add_action('wp_enqueue_scripts', 'my_theme_enqueue_scripts');`

Browser console shows: cookieconsent-init.js?ver=1.0.0:2 Uncaught ReferenceError: initCookieConsent is not defined at cookieconsent-init.js?ver=1.0.0:2:10

Grateful for your help and guidance.

@github-actions github-actions bot added the triage yet to be reviewed label Jan 5, 2024
@Mamunson
Copy link
Author

Mamunson commented Jan 6, 2024

This is did it and I thought I'd share it with you:

`// This will add CSS, jQuery and JavaScript
function my_theme_enqueue_scripts()
{
// Enqueue jQuery
wp_enqueue_script('jquery');
wp_enqueue_script('app-js', get_template_directory_uri() . '/js/app.js', array('jquery'), '1.0.0', true);
wp_enqueue_script('cookieconsent-js', get_template_directory_uri() . '/js/cookieconsent-init.js', array('jquery', 'app-js'), '1.0.0', true);
wp_enqueue_style('style-css', get_template_directory_uri() . '/style.css', array(), '1.0', 'all');
}

add_action('wp_enqueue_scripts', 'my_theme_enqueue_scripts');`

@Mamunson Mamunson closed this as completed Jan 6, 2024
@Mamunson
Copy link
Author

Mamunson commented Jan 6, 2024

Issue solved.

@orestbida orestbida removed the triage yet to be reviewed label Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants