2016-01-10 24 views
1

我試着在繼directions「我functons.php文件中enqueue scripts插入HTML代碼要使用熒光筆在您的網站,就可以在結束HTML下面的一行</head>標籤在您的網站的每個頁面應該有參考經文上找到」如何添加上面我的WordPress這個自定義HTML</head>標籤

<script id="bw-highlighter-config"> 
(function(w, d, s, e, id) { 
    w._bhparse = w._bhparse || []; 
    function l() { 
    if (d.getElementById(id)) return; 
    var n = d.createElement(s), x = d.getElementsByTagName(s)[0]; 
    n.id = id; n.async = true; n.src = '//bibles.org/linker/js/client.js'; 
    x.parentNode.insertBefore(n, x); 
    } 
    (w.attachEvent) ? w.attachEvent('on' + e, l) : w.addEventListener(e, l, false); 
})(window, document, 'script', 'load', 'bw-highlighter-src'); 
</script> 

這裏是我的排隊部分看起來像在functions.php我試圖結束ADD_ACTION功能前右側粘貼上面的HTML,但後來我被留下有兩個add_action函數和我的網站沒有正確加載?

/** 
* Enqueue scripts and styles. 
*/ 
function west_scripts() { 

     wp_enqueue_style('west-style', get_stylesheet_uri()); 

     if (get_theme_mod('body_font_name') !='') { 
      wp_enqueue_style('west-body-fonts', '//fonts.googleapis.com/css?family=' . esc_attr(get_theme_mod('body_font_name'))); 
     } else { 
      wp_enqueue_style('west-body-fonts', '//fonts.googleapis.com/css?family=Roboto:400,400italic,500italic,500'); 
     } 

     if (get_theme_mod('headings_font_name') !='') { 
      wp_enqueue_style('west-headings-fonts', '//fonts.googleapis.com/css?family=' . esc_attr(get_theme_mod('headings_font_name'))); 
     } else { 
      wp_enqueue_style('west-headings-fonts', '//fonts.googleapis.com/css?family=Montserrat:400,700'); 
     } 

     wp_enqueue_style('west-fontawesome', get_template_directory_uri() . '/fonts/font-awesome.min.css'); 

     wp_enqueue_script('west-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true); 

     if (is_singular() && comments_open() && get_option('thread_comments')) { 
       wp_enqueue_script('comment-reply'); 
     } 

     if (get_theme_mod('blog_layout') == 'masonry-layout' && (is_home() || is_archive())) { 
       wp_enqueue_script('west-masonry-init', get_template_directory_uri() . '/js/masonry-init.js', array('jquery-masonry'),'', true); 
     } 

     wp_enqueue_script('west-main', get_template_directory_uri() . '/js/main.js', array('jquery'), '', true); 

     wp_enqueue_script('west-scripts', get_template_directory_uri() . '/js/scripts.min.js', array('jquery'), '', true); 
} 
add_action('wp_enqueue_scripts', 'west_scripts'); 

回答

1

由於您使用的WordPress,你需要一些特殊的代碼添加到您的functions.php文件的末尾告訴WordPress的添加</head>標籤上面的HTML:

add_action('wp_head','add_bw_highlighter'); 

function add_bw_highlighter() { ?> 
    <script id="bw-highlighter-config"> 
    (function(w, d, s, e, id) { 
     w._bhparse = w._bhparse || []; 
     function l() { 
     if (d.getElementById(id)) return; 
     var n = d.createElement(s), x = d.getElementsByTagName(s)[0]; 
     n.id = id; n.async = true; n.src = '//bibles.org/linker/js/client.js'; 
     x.parentNode.insertBefore(n, x); 
     } 
     (w.attachEvent) ? w.attachEvent('on' + e, l) : w.addEventListener(e, l, false); 
    })(window, document, 'script', 'load', 'bw-highlighter-src'); 
    </script> 
<?php } 
相關問題