0

I want to Enqueue these links in WP.

http://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.11.1/jquery.validate.min.js

http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.7.1/modernizr.min.js

As you can see that they are live links and are not in my WP Server. I know how to correctly enqueue JS files residing in my own server.

So how to enqueue those live links correctly?

1 Answer 1

1

I perviously have answere similar question at Wordpess.Stackexchange

Its pretty simple.

First you have to add a function in your themes funcition.php file to register and enqueue your scripts in head using wp_enqueue_scripts hook.

// Register and enqueue all scripts in head
function custom_scripts() {

    wp_register_script( 'script_to_validate', 'http://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.11.1/jquery.validate.min.js', false, false, false );
    wp_enqueue_script( 'script_to_validate' );

    wp_register_script( 'script_modernizr', 'http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.7.1/modernizr.min.js', false, false, false );
    wp_enqueue_script( 'script_modernizr' );

}

// Hook into the 'wp_enqueue_scripts' action
add_action( 'wp_enqueue_scripts', 'custom_scripts' );  

Then you can call your function to initiate your script in footer using wp_footer hook as following;

// Add this in function.php as well
function call_script_in_footer(){
?>
<script>
// Add your related script over here
</script>
<?php
}

add_action( 'wp_footer', 'call_script_in_footer' );

And thats it. Now you can use this in any template you want.

Sign up to request clarification or add additional context in comments.

2 Comments

Ohh I see. So its basically same like we do with other JS files on server. Thank you Man :)
@InfiniteMystery If you found this answer helpful please vote up and mark it as correct answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.