wp_enqueue_style不适用于主题

时间:2019-02-14 20:44:03

标签: wordpress

我有库存的html模板。不能在functions.php文件中运行样式

来自html模板的示例

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Перевозки в Израиле</title>
    <link href="<?= bloginfo('template_directory'); ?>/css/bootstrap.min.css" rel="stylesheet">
    <link href="<?= bloginfo('template_directory'); ?>/css/template.css" rel="stylesheet">
    <link href="<?= bloginfo('template_directory'); ?>/css/icomoon.css" rel="stylesheet">
    <link href="<?= bloginfo('template_directory'); ?>/modules/slick/slick.css" rel="stylesheet">
    <link href="<?= bloginfo('template_directory'); ?>/modules/slick/slick-theme.css" rel="stylesheet">
    <link href="<?= bloginfo('template_directory'); ?>/modules/Magnific-Popup/magnific-popup.css" rel="stylesheet">
    <link href="<?= bloginfo('template_directory'); ?>/modules/vertical-timeline/css/style.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Montserrat:400,700%7COpen+Sans:100,300,400,700" rel="stylesheet">
    <link href="<?= bloginfo('template_directory'); ?>/modules/revolution/fonts/pe-icon-7-stroke/css/pe-icon-7-stroke.css" rel="stylesheet" type="text/css" >
    <link href="<?= bloginfo('template_directory'); ?>/modules/revolution/fonts/font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css" >
    <link href="<?= bloginfo('template_directory'); ?>/modules/revolution/css/settings.css" rel="stylesheet" type="text/css">
</head>

functions.php文件中的示例

function p24_scripts() {

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

wp_enqueue_style( 'p24-bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', false );

wp_enqueue_style( 'p24-template', get_template_directory_uri() . '/css/template.css', false );

wp_enqueue_style( 'p24-icomoon', get_template_directory_uri() . '/css/icomoon.css', false );

wp_enqueue_style( 'p24-slick', get_template_directory_uri() . '/modules/slick/slick.css', false );

wp_enqueue_style( 'p24-slick-theme', get_template_directory_uri() . '/modules/slick/slick-theme.css', false );

wp_enqueue_style( 'p24-magnific-popup', get_template_directory_uri() . '/modules/Magnific-Popup/magnific-popup.css', false );

wp_enqueue_style( 'p24-modules-style', get_template_directory_uri() . '/modules/vertical-timeline/css/style.css', false );

wp_enqueue_style( 'p24-pe-icon-7-stroke', get_template_directory_uri() . '/modules/revolution/fonts/pe-icon-7-stroke/css/pe-icon-7-stroke.css', false );

wp_enqueue_style( 'p24-font-awesome', get_template_directory_uri() . '/modules/revolution/fonts/font-awesome/css/font-awesome.css', false );

wp_enqueue_style( 'p24-settings', get_template_directory_uri() . '/modules/revolution/css/settings.css', false );

wp_enqueue_script( 'p24-jquery', get_template_directory_uri() . '/js/src/plugins/jquery-1.11.1.min.js', array(), '20151215', true );

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

} add_action('wp_enqueue_scripts','p24_scripts');

告诉我为什么样式不起作用?

3 个答案:

答案 0 :(得分:1)

声明了函数p24_scripts()后会调用它吗?
像这样:

  add_action( 'wp_enqueue_scripts', 'p24_scripts' );

无论如何,请检查控制台,其他请求可能会阻止页面加载。
尝试删除Google字体请求,看看这是否阻止了您的网页。

答案 1 :(得分:1)

您的代码正确。

请务必了解与...的区别

// get path url from the main theme    
get_template_directory_uri()

// get path url from the child theme or active theme
get_stylesheet_uri()

使用导航器控制台进行调试

答案 2 :(得分:0)

我有答案!我忘记了header.php文件中的<?php wp_head(); ?>