I know how to add custom/external js but i dont know how to pass js id also.
i am using it as:
wp_register_script( 'validation', 'https://www.asd.in/script.php?id=3ff00a469474bbe71a9218a7f0377518', array( 'jquery' ) );
wp_enqueue_script( 'validation' );
but I need output in footer like:
<script type="text/javascript" id="3ff00a469474bbe71a9218a7f0377518" src="https://www.asd.in/script.php?id=3ff00a469474bbe71a9218a7f0377518"></script>
Note: ID 3ff00a469474bbe71a9218a7f0377518 most show in output
1 Answer
You can use the script_loader_tag
hook
function enqueue_validation_script() {
wp_register_script( 'validation', 'https://www.asd.in/script.php?id=3ff00a469474bbe71a9218a7f0377518', array( 'jquery' ) );
wp_enqueue_script( 'validation' );
}
add_action('wp_enqueue_scripts', 'enqueue_validation_script');
function add_id_to_validation_script( $tag, $handle, $src ) {
if ( 'validation' === $handle ) {
$tag = '<script type="text/javascript" id="3ff00a469474bbe71a9218a7f0377518" src="'.$src.'"></script>';
}
return $tag;
}
add_filter( 'script_loader_tag', 'add_id_to_validation_script', 10, 3 );