douye7033 2015-11-12 13: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 13: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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部