Created
August 26, 2012 12:32
-
-
Save jester1979/3478545 to your computer and use it in GitHub Desktop.
Filter WP's script_loader_src
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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