Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress-Javascript排队_Javascript_Wordpress - Fatal编程技术网

Wordpress-Javascript排队

Wordpress-Javascript排队,javascript,wordpress,Javascript,Wordpress,我有一个wordpress网站,我知道要在wordpress页面上运行脚本,需要将脚本放入functions.php文件中。我不知道怎么做这个过程 我的Javascript名为boosting.js 有人能给我一个如何做到这一点的示例代码吗? 非常感谢你!(我对所有这些都有点陌生)您需要将其添加到functions.php 脚本名称-是要为脚本指定的名称 get_template_directory_uri()。'/js/boosting.js'-是脚本所在位置的路径。如果您使用的是子主题,则将

我有一个wordpress网站,我知道要在wordpress页面上运行脚本,需要将脚本放入functions.php文件中。我不知道怎么做这个过程

我的Javascript名为boosting.js 有人能给我一个如何做到这一点的示例代码吗?
非常感谢你!(我对所有这些都有点陌生)

您需要将其添加到functions.php

脚本名称
-是要为脚本指定的名称

get_template_directory_uri()。'/js/boosting.js'
-是脚本所在位置的路径。如果您使用的是子主题,则将其更改为
get\u stylesheet\u directory\u uri()/js/boosting.js'

array()
-这是用于依赖项的。如果您的脚本需要jQuery工作,请使用
array('jQuery')

1.0.0
-脚本的版本。用于缓存

true
-表示脚本将加载到页脚中,如果需要,请在页眉中使用
false

/**
 * Proper way to enqueue scripts and styles.
*/
function wp_theme_enque_scripts() {
    wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/boosting.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'wp_theme_enque_scripts' );

您可以在这里阅读更多内容

Hi,我在functions.php中搜索了所需的脚本如下:
function wp_theme_enque_scripts(){wp_enqueue_script('boosting',get_template_directory_uri()。/csgoboost/js/boosting.js',array('header'),'1.0.0',true);wp_enqueue_脚本('jquery get_template_directory_uri()).csgoboost/js/jquery.js',array('header'),'1.0.0',true);wp_enqueue_脚本('bootstrap',get_template_directory_uri()。/csgoboost/js/bootstrap.min.js',array('header'),'1.0.0',true);}添加_操作('wp_enqueue_脚本','wp_主题_enqueue_脚本')正确吗?不正确。JQuery由WordPress排队,所以您不需要这样做。将代码更改为:
函数wp_-theme_-enque_-scripts(){wp_-enqueue_-script('boosting',get_-template_-directory_-uri()。/csgoboost/js/boosting.js',array('jquery'),'1.0.0',true);wp_-enqueue_-script('bootstrap',get_-template_-directory_-uri()。/csgobootstrap/js/js/bootstrap/bootstrap.min.js',array(),'3.3.6('wp_enqueue_scripts'、'wp_theme_enque_scripts');
既然您要添加引导,那么您可能还需要添加css。在同一个函数中,还可以添加
wp_register_样式('Bootstrap.css',get_template_directory_uri()。'csgobootstrap/css/Bootstrap.css','3.3.6','all');wp_enqueue_样式('Bootstrap.css'));
检查它是否工作(如果使用的路径不正确,则可能不工作),刷新站点并查看源代码(CTRL+U)然后查找bootstrap css、js和boosting.js并单击它们。如果它们打开,那么使用的路径就很好。好的,所以我在css中添加了正确的函数,但是当我检查源代码时,没有bootstrap css、js和boosting.js。这可能是什么原因?如果get_template_directory_uri()
是对的……我很困惑