1

First, I would like to use Jplayer in Wordpress. I know that probably the procedure is very simple, but as I don't have much experience in WP, I'm having trouble.

The installation consists in tree steps (please check the link):

  1. Upload the jPlayer plugin
  2. Include jQuery
  3. Include jPlayer

1 is OK. I think I can skip 2, because I read that jQuery is already included in WP. Is this right? 3 confuses me a little bit. Should I put the code in theme's head.php?

2
  • Use wp_enqueue_script() to enqueue your scripts, read the codex, and though jQuery is used in WP, you have to enqueue it when developing a theme or plugin. Commented Dec 24, 2014 at 4:18
  • You know there's a player already included right? Commented Dec 24, 2014 at 6:00

1 Answer 1

0

After uploading the plugin file to a directory inside your theme, you will want to enqueue the plugin file in functions.php

You should already have a similar function in your functions.php file, but if you don't yo can add it. Change false to true if you want the file to load in the footer instead of the header. In this example I put the file inside a folder named 'js' inside my theme folder.

//Enqueue scripts
function register_scripts() {
      wp_enqueue_script('jplayer',get_template_directory_uri().'/js/jquery.jplayer.min.js',null,'1',false);

}

add_action('wp_enqueue_scripts','register_scripts');


//Enqueue styles
function register_styles() {

     //($handle, $src, $deps, $ver, $media)
    wp_enqueue_style('main_style',get_template_directory_uri().'/style.css?v=1',null,'0.1', $media = 'all');


}

add_action('wp_enqueue_scripts','register_styles');
4
  • Thanks! Just one more questions: let's say I wan't to add one more script. In particular, I will try to follow this tutorial: linge-ma.ws/…. Can I enqueue it in the same function that you posted? What's the right way to do that?
    – ProjRec
    Commented Dec 23, 2014 at 20:53
  • Just add another wp_enqueue_script, just make sure that the first argument (in this case 'jplayer') is never the same. You can use anything, but it has to be unique.
    – gdaniel
    Commented Dec 23, 2014 at 21:03
  • Thank you again! Now I have to include the CSS: jplayer.org/latest/quick-start-guide/step-5 . May you please tell me the right way to do that? I've been reading some tutorials about CSS in WP but I am not sure.
    – ProjRec
    Commented Dec 24, 2014 at 2:23
  • Same thing for styles. Except that you need to use wp_enqueue_style. I updated my answer.
    – gdaniel
    Commented Dec 24, 2014 at 15:31

Your Answer

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

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