如何将引导脚本正确注册到WordPress unctions.php中?

时间:2013-11-15 作者:Charles

我对bootstrap和WordPress还不熟悉,我正在尝试将一个简单的页面组合在一起。因此,我在添加和注册来自页眉和页脚的脚本时遇到依赖性问题并不奇怪。

这里有什么明显的东西我遗漏了吗?

<?php 
function wpbootstrap_scripts_with_jquery() { // Register the script like this for a theme: wp_register_script( \'custom-script\', get_template_directory_uri() . \'js/bootstrap.js\', array( \'jquery\' ) );

// Register the script like this for a theme:
wp_register_script( \'custom-script\', get_template_directory_uri() . \'js/jquery.tweet.js\', array( \'jquery\' ) );


// Register the script like this for a theme:
wp_register_script( \'custom-script\', get_template_directory_uri() . \'js/clock.js\', array( \'jquery\' ) );


// Register the script like this for a theme:
wp_register_script( \'custom-script\', get_template_directory_uri() . \'js/soon.js\', array( \'jquery\' ) );
//footer scripts

// Register the script like this for a theme:
wp_register_script( \'custom-script\', get_template_directory_uri() . \'js/dat.gui.min.js\', array( \'jquery\' ) );


// Register the script like this for a theme:
wp_register_script( \'custom-script\', get_template_directory_uri() . \'js/fss.js\', array( \'jquery\' ) );


// Register the script like this for a theme:
wp_register_script( \'custom-script\', get_template_directory_uri() . \'js/bgCustom.js\', array( \'jquery\' ) );


// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script( \'custom-script\' );
} add_action( \'wp_enqueue_scripts\', \'wpbootstrap_scripts_with_jquery\' );

?>

1 个回复
最合适的回答,由SO网友:Nicolai Grossherr 整理而成

wp_register_script() codex页面句柄:

应是唯一的,因为它用作句柄,以便以后与wp\\u enqueue\\u script()一起使用。

您正在对所有脚本使用相同的句柄,这将不起作用。

除此之外,如果这些脚本依赖于引导,您至少必须在之前注册引导,并将其作为依赖项添加到自定义脚本注册中。或者,在使用wp_enqueue_script(), 它还有一个dependencies参数。在链接的页面上阅读有关用法的更多信息。

结束

相关推荐

只在本地主机上运行的Functions.php代码?

我想在函数中运行add\\u操作。仅当主题是从我的localhost开发站点加载时才使用php。如何使其仅在本地主机上运行?function livereload(){ ?> // mycode <?php } add_action(\'headway_body_close\', \'livereload\');