Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I found Morris.js to be a delightfully implemented charting script, and wanted to include it in my Wordpress installation. But I have never included a js file with my blog before, and would appreciate if someone can guide me on this:

  1. How do I include the javascript file?
  2. Where do I upload it on the server?
  3. Anything else I need to know to use it?

Thanks.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Create js folder in your theme directory then save Morris.js into it. it is not mandatory to store it in js folder you can store it anywhere else but i recommend to do it to seprate javascipt files from other files.

Add follwing action into functions.php file

function custom_scripts() {
/* Include Scripts */
wp_enqueue_script( 'morris-script', get_template_directory_uri() . '/js/Morris.js', array( 'jquery' ), '', true );
}
add_action( 'wp_enqueue_scripts', 'custom_scripts' );

You can find more information about wp_enqueue_script() function from this link http://codex.wordpress.org/Function_Reference/wp_enqueue_script of wordpress codex.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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