Skip to content

Instantly share code, notes, and snippets.

@jester1979
Created August 26, 2012 12:32
Show Gist options
  • Save jester1979/3478545 to your computer and use it in GitHub Desktop.
Save jester1979/3478545 to your computer and use it in GitHub Desktop.
Filter WP's script_loader_src
<?php
add_filter( 'script_loader_src', 'my_script_loader_filter' );
/**
* function for filter 'script_loader_src' it echo's a script-tag with it's src empty. the src is kept in data-src so javascript can put in the src-attr on a later moment. (e.g. after a cookie-check)
*
* @author Floris P. Lof
* @params String $src the current source of the scriptfile to be included
* @return Boolean false
*/
function my_script_loader_filter( $src ) {
echo '<script type="text/javascript" src="" data-src="' . esc_url( $src ) . '"></script>' . PHP_EOL;
return false; //unfortunately this also leaves you with an extra blank script-tag in your DOM :-(
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment