簡體   English   中英

WordPress-排隊腳本/ CSS出現問題

[英]WordPress - Trouble with enqueue-ing scripts/CSS

因此,我已經很長時間沒有使用Wordpress了,而我正試圖重新回到現實中。 顯然,處理外部CSS / JS的正確方法是使用wp_register_stylewp_enqueue_stylewp_register_scriptwp_enqueue_script ……但是它們根本不適合我。

以下是我當前的functions.php

<?php

    // Enqueue necessary scripts/etc.
    function wasd_styles() {
        wp_register_style('semantic-css', get_stylesheet_directory_uri() . '/lib/semantic.min.css');
        wp_enqueue_style('semantic-css');
    }

    function wasd_scripts() {
        wp_register_script('semantic-js', get_template_directory_uri() . '/lib/semantic.min.js');
        wp_enqueue_script('semantic-js');
    }

    add_action('wp_enqueue_scripts', 'wasd_styles');
    add_action('wp_enqueue_scripts', 'wasd_scripts');

?>

我做錯了什么嗎? 據我所知,它應該注入適當的調用以將CSS / JS捕獲到我的頁面標簽中,但是不是。

以下是我要渲染的兩個文件,我在5分鍾內將它們放在一起以嘗試測試語義UI,但它根本無法正常工作,沒有渲染任何樣式,並且在檢查源代碼時為空。

index.php

<?php get_header(); ?>

<div class="ui main container">
    <h2 class="ui dividing header">This is a test</h2>
</div>

header.php

<div class="ui top fixed inverted menu">
    <div class="item">Test</div>
</div>

根據您共享的代碼,您的主題不支持使用wp_enqueue_script() 此函數僅注冊腳本並准備將其插入DOM。 這是通過掛鈎插入的,該掛鈎似乎未出現在您的主題中。 您需要將以下內容添加到header.php文件中。 通常將其添加在<head></head>標記之間。

<?php wp_head(); ?>

另外,您的footer.php文件中應該有一個類似的鈎子,通常在</body>標記之前。 該鈎子將是:

<?php wp_footer(); ?>

沒有這些, wp_enqueue_script()wp_enqueue_style()將不起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM