2

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

3
  • Can you please explain why you need to pass JS id? Nov 21 '17 at 10:37
  • @Pratikbhatt this is a API and not working with ID, i don't know they are using it :(
    – Shiv Singh
    Nov 21 '17 at 10:42
  • 1
    solved by: child_theme_footer_script()
    – Shiv Singh
    Nov 21 '17 at 11:35
1

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 );
3
  • Not working this and not showing anything.
    – Shiv Singh
    Nov 21 '17 at 10:50
  • you need to enqueue the scripts too...
    – Shibi
    Nov 21 '17 at 10:58
  • i have solved by : child_theme_footer_script();
    – Shiv Singh
    Nov 21 '17 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.