script_loader_src
云策文档标注
概述
script_loader_src 是一个 WordPress 过滤器,用于修改脚本加载器的源路径。它允许开发者在脚本加载时动态调整其 URL,常用于移除查询字符串或自定义脚本源。
关键要点
- 过滤器名称:script_loader_src
- 参数:$src(脚本源路径字符串)和 $handle(脚本句柄字符串)
- 用途:过滤脚本加载器的源路径,例如移除版本查询字符串或替换脚本源
- 引入版本:WordPress 2.2.0
- 相关函数:wp_get_script_polyfill() 和 WP_Scripts::do_item()
代码示例
// 从静态 jQuery 文件中移除查询字符串
function remove_query_string_from_static_jquery_files( $src ) {
if( strpos( $src, '?ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'script_loader_src', 'remove_query_string_from_static_jquery_files', 10 );
原文内容
Filters the script loader source.
Parameters
$srcstring-
Script loader source path.
$handlestring-
Script handle.
Source
$filtered_src = apply_filters( 'script_loader_src', $src, $handle );
Changelog
| Version | Description |
|---|---|
| 2.2.0 | Introduced. |
Skip to note 2 content
Ravi Makwana
// Remove query string from static jquery files function remove_query_string_from_static_jquery_files( $src ) { if( strpos( $src, '?ver=' ) ) $src = remove_query_arg( 'ver', $src ); return $src; } add_filter( 'script_loader_src', 'remove_query_string_from_static_jquery_files', 10 );