【问题标题】:style.css not loading in wordpress themestyle.css 未在 wordpress 主题中加载
【发布时间】:2025-11-27 14:20:08
【问题描述】:

这是我在 wordpress 主题中不起作用的代码。使用此代码尝试从 wp 根文件夹获取 style.css 文件。这段代码有什么问题是函数名不正确

<?php
function add_style() { wp_enqueue_style('style', get_stylesheet_uri()); }
add_action('wp_enqueue_scripts','add_style');
?>

但是 wp 函数文件中的这段代码工作正常

register_nav_menus(array(
    'primary' => __('Primary Menu')
    )) ;

那么谁能帮帮我?

【问题讨论】:

    标签: php css wordpress styles


    【解决方案1】:
    function custom_scripts_method() {
    
      /*  CSS  */
      wp_enqueue_style( 'boostrap-style', get_template_directory_uri().'path to file from theme folder' ); 
    
    }       
    
    add_action( 'wp_enqueue_scripts', 'custom_scripts_method' );
    
    ?>
    

    在functions.php文件中添加这个

    记得使用:&lt;?php wp_head(); ?&gt; 在你的 html 的头部

    【讨论】:

    • 请不要只发布一些代码作为答案。最好也说明问题所在以及您的代码如何解决问题。
    • 谢谢@Alexander 我解决了我的问题我试图在 index.php 上应用 css 而不使用 wp_Head() 谢谢
    【解决方案2】:
    <link href="<?php bloginfo('stylesheet_url');?>" rel="stylesheet">
    

    将此添加到您的 header.php 中

    【讨论】: