douye7033 2015-11-12 21:28
浏览 66
已采纳

WordPress - 排队脚本/ CSS的麻烦

So, I've not used Wordpress in a long time, and I'm trying to get back into the swing of things. Apparently the correct way to deal with external CSS/JS is to enqueue them using wp_register_style, wp_enqueue_style, wp_register_script, and wp_enqueue_script... but they're not working for me at all.

The following is my current 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');

?>

Is there something I'm doing wrong? As far as I can tell, it should be injecting the proper calls to grab CSS/JS into the tag of my page, but..it's not.

The following are the two files I'm attempting to render, I threw this together in like 5 minutes to attempt to test Semantic UI, but it's just not working at all, no style is being rendered, and is empty upon source inspection.

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>
  • 写回答

1条回答 默认 最新

  • dongyuntao2000 2015-11-12 21:36
    关注

    From the code you have shared, your theme does not support the use of wp_enqueue_script(). This function simply registers the scripts and gets it ready for insertion into the DOM. This is inserted via a hook, which doesn't appear to be present in your theme. You would need to add the following into your header.php file. This would typically be added between the <head></head> tags.

    <?php wp_head(); ?>

    Also, you should have a similar hook in your footer.php file, typically just before the closing </body> tag. This hook would be:

    <?php wp_footer(); ?>

    Without these, wp_enqueue_script() and wp_enqueue_style() will not work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭