gpt4 book ai didi

javascript - Wordpress 音频播放器和 SmoothState。在回调中调用什么以在新页面上重新加载播放器?

转载 作者:搜寻专家 更新时间:2023-11-01 04:40:41 25 4
gpt4 key购买 nike

我在“header.php”页面的代码中使用带有简码的 Wordpress 音频播放器。

我也在使用 SmoothState ( http://miguel-perez.github.io/smoothState.js/ )。

我必须在“回调”上调用什么函数才能在新页面上重新加载播放器?

我像这样在 functions.php 中排队 js 和 css:

wp_enqueue_style( 'wp-mediaelement' );
wp_enqueue_script( 'wp-mediaelement' );

最佳答案

wp_enqueue_script(); 所做的只是在检查依赖项后将脚本放入您的页面。它不会在不同的页面上为您重新加载播放器。但是,只要您正确使用此功能,您的脚本就会在每个页面上加载。也许您的错误在别处?

From the WordPress documentation on wp_enqueue_script(); :

Links a script file to the generated page at the right time according to the script dependencies, if the script has not been already included and if all the dependencies have been registered.

如果 Wordpress Audio Player 有 jQuery 作为依赖项(可能),您的 functions.php 文件应该如下所示:

function wpaudioscript() {
// Parameters are name, path, dependency, version, loadinfooter
// Better explanation here: http://codex.wordpress.org/Function_Reference/wp_enqueue_script
wp_enqueue_script(
'name-of-script',
get_stylesheet_directory_uri() . '/js/custom_script.js',
array( 'jquery' ),
1.0.0,
true
);
}

add_action( 'wp_enqueue_scripts', 'wpaudioscript' );

其他注意事项:

  • 您应该将脚本加载到应用程序的页脚中以获得更好的性能。将 wp_enqueue_script 的第五个参数设置为 true,如上例所示,将为您执行此操作。
  • 许多人通常将这样的自定义功能放入他们的 functions.php 文件中,但我发现将您自己的所有修改放入自定义模块中会更简洁。 Smashing Mag a nice rundown of how to do this .

关于javascript - Wordpress 音频播放器和 SmoothState。在回调中调用什么以在新页面上重新加载播放器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33307274/

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