【问题标题】:How to add JS & CSS to wordpress page如何将 JS 和 CSS 添加到 wordpress 页面
【发布时间】:2016-08-24 15:30:18
【问题描述】:

我有一个包含 js 和 CSS 文件的小代码。我的网站是一个 wordpress 网站,我想将代码添加到我的一个页面中。

我想知道应该将 JS 代码和 CSS 代码放在一个已经制作好的 wordpress 文件中,还是必须将它们放在目录中?

另外,为了实现代码,我需要在某处保存一些数组,以便脚本可以回调数组。我在哪里放置数组?

【问题讨论】:

  • 转到已被回答一千次的google.com
  • 在您的主题中查看functions.php

标签: javascript jquery css wordpress


【解决方案1】:

将脚本和样式添加到主题的正确方法是将它们排入 functions.php 文件中。

function add_theme_scripts() {
  wp_enqueue_style( 'style', get_stylesheet_uri() );

  wp_enqueue_style( 'slider', get_template_directory_uri() . '/css/slider.css', array(), '1.1', 'all');

  wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', array ( 'jquery' ), 1.1, true);


add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );

欲了解更多信息,请阅读此文档:https://developer.wordpress.org/themes/basics/including-css-javascript/

【讨论】:

    猜你喜欢
    • 2021-11-29
    • 2010-11-07
    • 2011-02-18
    • 2014-03-02
    • 2012-12-26
    • 2020-09-21
    • 2014-06-28
    • 2017-02-17
    • 2018-11-30
    相关资源
    最近更新 更多