gpt4 book ai didi

javascript - 损坏的函数.php;如何将脚本从 bootstrap 移动到 WordPress?

转载 作者:行者123 更新时间:2023-11-30 17:46:40 25 4
gpt4 key购买 nike

我是 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' ) );
wp_register_script( 'jquery-tweet', get_template_directory_uri() . 'js/jquery.tweet.js', array( 'jquery' ) );
wp_register_script( 'clock', get_template_directory_uri() . 'js/clock.js', array( 'jquery' ) );
wp_register_script( 'soon', get_template_directory_uri() . 'js/soon.js', array( 'jquery' ) );

//footer scripts
wp_register_script( 'dat-gui-min-js', get_template_directory_uri() . 'js/dat.gui.min.js' );
wp_register_script( 'fss', get_template_directory_uri() . 'js/fss.js');
wp_register_script( 'bgCustom', get_template_directory_uri() . 'js/bgCustom.js');


// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script( 'custom-script','jquery-tweet','clock','soon','dat-gui-min-js','fss','bgCustom');
}

add_action( 'wp_enqueue_scripts', 'wpbootstrap_scripts_with_jquery' );

?>

在 header.php 中

<?php wp_enqueue_script("jquery"); ?>
<?php wp_head(); ?>

最佳答案

我相信您需要为使用 wp_register_script 注册的每个脚本起一个唯一的名称。例如,您将它们全部命名为“custom_script”。我会给每一个命名与其 JavaScript 文件相同的名称(只是为了方便)。例如……

wp_register_script( 'jquery-tweet', get_template_directory_uri() . 'js/jquery.tweet.js', array( 'jquery' ) );
wp_register_script( 'clock', get_template_directory_uri() . 'js/clock.js', array( 'jquery' ) );

...等等。然后你会像这样将每一个排队......

wp_enqueue_script( 'jquery-tweet' );
wp_enqueue_script( 'clock' );

...等等

希望对您有所帮助,玩得开心!

关于javascript - 损坏的函数.php;如何将脚本从 bootstrap 移动到 WordPress?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20007811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com