2017-05-05 106 views
0

我試圖將一個腳本加載到一個WordPerss頁面,但它似乎排隊腳本不會添加任何東西。WordPress排隊腳本不添加腳本

我用下面的腳本

function loadCC(){ 
    wp_enqueue_script('cookieConsentJS', 'https://cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js'); 
    wp_enqueue_style('cookieConsentCSS', 'https://cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css'); 

    wp_add_inline_script("CookieConsent", "window.addEventListener(\"load\", function(){ 
    window.cookieconsent.initialise({ 
     \"palette\": { 
      \"popup\": { 
       \"background\": \"#107fc9\" 
      }, 
      \"button\": { 
       \"background\": \"#ffffff\" 
      } 
     }, 
     \"position\": \"top\", 
     \"static\": true, 
     \"content\": { 
      \"message\": \"".__("Deze website maakt gebruik van cookies om authenticatie, navigatie en andere functies te beheren. Door het gebruik van onze website, gaat u ermee akkoord dat we dit soort cookies plaatsen op uw apparaat.","bpm_cc")."\", 
      \"dismiss\": \"".__("Ik begrijp het","bpm_cc")."\" 
     }, 
     \"elements\": { 
      \"messagelink\": \"<span id=\\\"cookieconsent:desc\\\" class=\\\"cc-message\\\">{{message}}</span>\", 
      \"dismiss\": \"<a aria-label=\\\"dismiss cookie message\\\" role=button tabindex=\\\"0\\\" class=\\\"vc_gitem-link vc_btn3 vc_btn3-size-md vc_btn-white\\\">{{dismiss}}</a>\"} 
     }) 
    });"); 
} 

add_action('wp_enqueue_scripts', 'loadCC'); 

難道我犯了一個錯誤的地方?代碼似乎對我來說是正確的。

+0

嘗試改變' wp_enqueue_style('wp_enqueue_scripts','to'wp_enqueue_style('wp_enqueue_scripts2','。If if it works it is a name conflict。 –

+0

我錯誤地複製了句柄,他們假設是cookieConsentJS和cookieConsentCSS而不是wp_enqueue_scripts我會在問題中做出解釋,但是不能解決問題 –

+1

任何錯誤rs在控制檯? –

回答

0

好一些調試,我發現該錯誤是在wp_add_inline_script部分後, 該手柄必須是一樣wp_enqueue_script(atlease這種變化之後它的工作原理)

<?php 
/** 
* Plugin Name: Cookie Consent 
* Version: 1 
* Author: Jasper (Bottle Post Media) 
*/ 
function loadCC(){ 
    wp_enqueue_script('CookieConsentJS', 'https://cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js'); 
    wp_enqueue_style('CookieConsentCSS', 'https://cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css'); 
    wp_add_inline_script("CookieConsentJS", "window.addEventListener(\"load\", function(){ 
    window.cookieconsent.initialise({ 
    \"palette\": { 
    \"popup\": { 
     \"background\": \"#107fc9\" 
    }, 
    \"button\": { 
     \"background\": \"#ffffff\" 
    } 
    }, 
    \"position\": \"top\", 
    \"static\": true, 
    \"content\": { 
    \"message\": \"".__("Deze website maakt gebruik van cookies om authenticatie, navigatie en andere functies te beheren. Door het gebruik van onze website, gaat u ermee akkoord dat we dit soort cookies plaatsen op uw apparaat.","bpm_cc")."\", 
    \"dismiss\": \"".__("Ik begrijp het","bpm_cc")."\" 
    }, 
    \"elements\": { 
    \"messagelink\": \"<span id=\\\"cookieconsent:desc\\\" class=\\\"cc-message\\\">{{message}}</span>\", 
    \"dismiss\": \"<a aria-label=\\\"dismiss cookie message\\\" role=button tabindex=\\\"0\\\" class=\\\"vc_gitem-link vc_btn3 vc_btn3-size-md vc_btn-white\\\">{{dismiss}}</a>\"}})});"); 
} 

add_action('wp_enqueue_scripts', 'loadCC'); 
0

檢查您的主題header.php文件。它應該包含wp_head();之間的功能head html標籤。

0

嘗試改變這一點:

`wp_add_inline_script("CookieConsent", "window.addEventListener(\"load\", function(){ 
    window.cookieconsent.initialise({ 
    \"palette\": { 
    \"popup\": { 
    \"background\": \"#107fc9\" 
      },` 
在此

,也許你錯過了一個支架?

wp_add_inline_script("CookieConsentJS", "window.addEventListener(\"load\", function(){ 
window.cookieconsent.initialise({ 
\"palette\": { 
\"popup\": { 
\"background\": \"#107fc9\" 
} 
     },