Title: Adding wp_head() function to website’s header
Last modified: March 20, 2024

---

# Adding wp_head() function to website’s header

 *  Resolved [georgiedavies](https://wordpress.org/support/users/georgiedavies/)
 * (@georgiedavies)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/adding-wp_head-function-to-websites-header/)
 * Hi
 * I need to add wp_head() function to the website’s header to enable Google Consent
   Mode on my website. As I am not a developer I would prefer not to add directly
   to the header script and instead use Code Snippets so it is easily seen and tracked
   for me. Is this possible?
 * For your reference it is Method 2 of this documentation that I need to follow
   [https://www.cookieyes.com/documentation/implementing-google-consent-mode-using-cookieyes/#Method_2_I_6](https://www.cookieyes.com/documentation/implementing-google-consent-mode-using-cookieyes/#Method_2_I_6)
 * Thanks in advance

Viewing 1 replies (of 1 total)

 *  [generosus](https://wordpress.org/support/users/generosus/)
 * (@generosus)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/adding-wp_head-function-to-websites-header/#post-17538025)
 * Hey [@georgiedavies](https://wordpress.org/support/users/georgiedavies/),
 * Try the code snippet provided below.
 * Give it a spin. Let us know if it works.
 * If it does, can you kindly close this topic as “Resolved”?
 * Cheers!
 * ———————-
 * **References:**
    1. [https://www.wpbeginner.com/wp-tutorials/how-to-easily-add-javascript-in-wordpress-pages-or-posts/](https://www.wpbeginner.com/wp-tutorials/how-to-easily-add-javascript-in-wordpress-pages-or-posts/)
    2. [https://www.cookieyes.com/documentation/implementing-google-consent-mode-using-cookieyes/#Method_2_I_6](https://www.cookieyes.com/documentation/implementing-google-consent-mode-using-cookieyes/#Method_2_I_6)
 * ———————-
 *     ```wp-block-code
       function wpb_hook_javascript() {
           ?>
   
       <script>
   
           window.dataLayer = window.dataLayer || [];
           function gtag() {
               dataLayer.push(arguments);
           }
           gtag("consent", "default", {
               ad_storage: "denied",
               ad_user_data: "denied", 
               ad_personalization: "denied",
               analytics_storage: "denied",
               functionality_storage: "denied",
               personalization_storage: "denied",
               security_storage: "granted",
               wait_for_update: 2000,
           });
           gtag("set", "ads_data_redaction", true);
           gtag("set", "url_passthrough", true);
   
       </script>
   
           <?php
       }
       add_action('wp_head', 'wpb_hook_javascript');
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Adding wp_head() function to website’s header’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [generosus](https://wordpress.org/support/users/generosus/)
 * Last activity: [2 years, 2 months ago](https://wordpress.org/support/topic/adding-wp_head-function-to-websites-header/#post-17538025)
 * Status: resolved