filtrod 4.1.0
script_loader_tag
Opis
Modyfikuje tag <script> generowany przez WordPress — pozwala dodać atrybuty async lub defer.
Przykład użycia
add_filter( 'script_loader_tag', ... )php
add_filter( 'script_loader_tag', 'wpdocs_defer_scripts', 10, 3 );
function wpdocs_defer_scripts( $tag, $handle, $src ) {
if ( 'wpdocs-script' !== $handle ) {
return $tag;
}
return str_replace( ' src', ' defer src', $tag );
}
add_filter( 'script_loader_tag', 'wpdocs_defer_scripts', 10, 3 );
function wpdocs_defer_scripts( $tag, $handle, $src ) {
if ( 'wpdocs-script' !== $handle ) {
return $tag;
}
return str_replace( ' src', ' defer src', $tag );
}Parametry
| Parametr | Typ | Opis |
|---|---|---|
$tag | string | The <code><script></code> tag for the enqueued script. |
$handle | string | The script's registered handle. |
$src | string | The script's source URL. |
Wywołanie
Rejestracja callbackaphp
// rejestracja funkcji zwrotnej — podaj liczbę argumentów!
add_filter( 'script_loader_tag', 'twoja_funkcja', 10, 3 );
function twoja_funkcja($param_1, $param_2, $param_3) {
// Twój kod
}
// rejestracja funkcji zwrotnej — podaj liczbę argumentów!
add_filter( 'script_loader_tag', 'twoja_funkcja', 10, 3 );
function twoja_funkcja($param_1, $param_2, $param_3) {
// Twój kod
}Popularne w tej kategorii