How To Add Cookies To WordPress Without Plugin (With And Without Plugin)

Last update: 04/10/2024
How To Add Cookies To WordPress Without Plugin (With And Without Plugin)

Would you like to learn how to add cookies to WordPress without plugin? Cookies are small files that the sites you visit place on your computer's hard drive. They can identify you from one passage to another on the Internet. They follow you, they stalk you to find out your habits, to offer you a better choice in your actions, in other words, they spy on you: vast debate!

Cookies are placed on a desktop or laptop computer, but also on tablets, smartphone, even on consoles video games connected to the Internet… Some cookies may record your personal information, such as Google Analytics, share buttons, advertising networks…

We will not present all the articles of the law here, we will be brief. The CNIL specifies that all personal information that can be consulted electronically must first have the consent of the person.

Most sites use tracking tools like Google Analytics, so since the latest law you have to comply and ask for your visitors' consent when they visit your site. The method for this is to display an alert/information message to notify your visitors that you are going to save cookies on their computers.

Solution to create a cookie alert message to WordPress without a plugin

Let's see how to create a cookie alert message in WordPress without a plugin. These methods are very efficient for your website.

Here you can learn about: How to Change, Edit and Remove Copyright in WordPress Footer

Using the Cookie Notice Plugin in WordPress without a plugin

There are several WordPress plugins to display an alert or a message indicating to users the existence of cookies on their site, here we will present the best of this category. Cookies notice by dFactory.

How To Add Cookies To WordPress Without Plugin (With And Without Plugin)
Cookie Notice allows you to inform users that your site uses cookies and comply with European cookie law.

Features included in the WordPress cookie notice without plugin:

  • personalize the message
  • Redirect users to a specific page to learn more about cookies.
  • Establish There Cookie expiration
  • Link to additional information page
  • Option to accept cookies when scrolling down
  • Option to set the length of the offset before acceptance
  • Option to reject cookie functions
  • Option to reload the page after cookies are accepted
  • Choose the position of the warning about the use of cookies
  • Animate warning message after acceptance
  • Choose a button style
  • Set the text and background color of the message
  • Supports multilingual extensions WPML and Polylang
  • Friendly with SEO
  • Pot file for translations included
  How to Create a Forum in Wordpress | Installing Simple Press Forum

After installing the extension (Cookie Notice), if you don't want to do anything, leave it as is and you will have a black banner at the top of your site informing the Internet user that your site uses cookies.

You can also customize the Cookie Notice plugin:

  • modifying the sentence
  • taking the Internet user to a page on your blog such as your legal notices for example, which should include a cookie notice,
  • by placing the banner in the colors of your site and placing it at the top or bottom of your pages,
  • choosing the button style,
  • Cookie expiration (by default one month)

Add a cookie message to your site without a plugin

As you may know, multiplying plugins in your WordPress installation is not the best solution in terms of performance, because more plugins means an increase in your site's loading time.

Now, here are the steps to add a cookie consent bar in child themes based on the famous Genesis parent theme (it works for other WordPress themes as well). Let’s see the steps:

Step 1 to add cookie notices to WordPress without plugin

Go to this site in this LINK and set the cookie consent layout and compliance type. You can see the live preview.

Stage 2 to add cookie notices to WordPress without plugin

  • Step 1:: Open the file functionsphp from your child theme and add the following:

1

2

3

4

5

6

7

8

9

10

11

add_action( 'wp_head', 'custom_cookie_consent' );

/ **

* Add Cookie Consent bar in WordPress.

*

* @link https://cookieconsent.insites.com/download/

*/

function custom_cookie_consent() { ?>

<?php }

  • Step 2:: Copy the cookie consent code from the site and paste it after the line . Below is an example of the final result:
1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

add_action( 'wp_head', 'custom_cookie_consent' );

/ **

* Add Cookie Consent bar in WordPress.

*

* @link https://cookieconsent.insites.com/download/

*/

function custom_cookie_consent() { ?>

<link rel=»stylesheet» type=»text/css» href=»https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.css»/>

<script src=»https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.js» data-cfasync=»false»>

window.cookieconsent.initialize({

«palette»: {

«popup»: {

«background»: «#343c66»,

«text»: «#cfcfe8»

},

«button»: {

«background»: «#f71559»

}

},

«theme»: «edgeless»,

«position»: «bottom-left»

});

<?php }

  • Step 3:: Now go back to your site, you should see your cookie alert message in the location you have chosen according to your plugin settings.

You can also read about: How To Restrict Pages In WordPress

Conclusion

As you can see, this is how to create a cookie alert message in WordPress without a plugin. We recommend that you follow the steps to the letter so that there are no compilation errors within the code. We hope we have helped you with this information.

  Sports marketing: strategies, types, examples and training