WP HOOKS
filtrod 4.1.0

script_loader_tag

Args 3Plik wp-includes/class-wp-scripts.phpDokumentacja WP ↗

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 );
}

Parametry

ParametrTypOpis
$tagstringThe <code>&lt;script&gt;</code> tag for the enqueued script.
$handlestringThe script's registered handle.
$srcstringThe 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
}

Popularne w tej kategorii