函数文档

wp_playlist_scripts()

💡 云策文档标注

概述

wp_playlist_scripts() 函数用于输出和入队播放列表的默认脚本和样式。它接受一个参数指定播放列表类型,并自动处理相关资源加载。

关键要点

  • 函数 wp_playlist_scripts($type) 入队播放列表所需的默认脚本和样式。
  • 参数 $type 为字符串类型,必需,指定播放列表类型,接受 'audio' 或 'video'。
  • 函数内部调用 wp_enqueue_style('wp-mediaelement') 和 wp_enqueue_script('wp-playlist') 来入队资源。
  • 添加动作钩子 wp_footer 和 admin_footer 以加载播放列表模板。
  • 自 WordPress 3.9.0 版本引入。

代码示例

function wp_playlist_scripts( $type ) {
    wp_enqueue_style( 'wp-mediaelement' );
    wp_enqueue_script( 'wp-playlist' );
    add_action( 'wp_footer', 'wp_underscore_playlist_templates', 0 );
    add_action( 'admin_footer', 'wp_underscore_playlist_templates', 0 );
}

注意事项

  • 确保在需要播放列表功能时调用此函数,以避免资源缺失。
  • 参数 $type 必须为 'audio' 或 'video',否则可能导致播放列表类型错误。
  • 函数自动处理前端和管理后台的模板加载,无需手动干预。

📄 原文内容

Outputs and enqueues default scripts and styles for playlists.

Parameters

$typestringrequired
Type of playlist. Accepts 'audio' or 'video'.

Source

function wp_playlist_scripts( $type ) {
	wp_enqueue_style( 'wp-mediaelement' );
	wp_enqueue_script( 'wp-playlist' );
	add_action( 'wp_footer', 'wp_underscore_playlist_templates', 0 );
	add_action( 'admin_footer', 'wp_underscore_playlist_templates', 0 );
}

Changelog

Version Description
3.9.0 Introduced.