簡體   English   中英

CSS未與WordPress中的HTML鏈接

[英]CSS are not linking with HTML in WordPress

我計划在WordPress頁面中插入垂直滾動菜單。

我已采取的步驟:

步驟1:創建了一個文件夾,並將所有CSS和javascript文件粘貼到該文件夾​​中。

步驟2:在Wordpress中,我添加了一個新頁面,並且在html部分中添加了html代碼,並正確鏈接了樣式表和javascript

例如:

    <link rel="stylesheet" href="css/reset.css"> 
<link rel="stylesheet" href="css/style.css">
<script src="js/modernizr.js"></script>

在WordPress中,您需要指定這樣的鏈接:-

<link href="<?php echo get_template_directory_uri(); ?>/css/reset.css" type="text/css" rel="stylesheet">

希望這對您有用。

這是在子主題中使用正確的入隊原則的示例。

add_action( 'wp_enqueue_scripts', 'child_enqueue_styles');

function child_enqueue_styles() {

    wp_enqueue_style( 'reset-style', get_template_directory_uri() . '/css/reset.css', array());
}

這會將reset.css樣式添加到WordPress中的每個頁面。

那不是應該將cssjs文件調用到wp文件系統中的方式。 您應該在wp-content/themes/yourtheme找到functions.php文件。

看一下nex鏈接https://developer.wordpress.org/reference/functions/wp_enqueue_style/

function wpdocs_theme_name_scripts() {
    wp_enqueue_style( 'style-name', get_stylesheet_uri() );
    wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );

暫無
暫無

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

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