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 want to add small effect (UI-jquery-draggable) to the navigation buttons in one of the WP slider plugins.

what i did:

1 I have installed the slider plugin

2 know that UI is allredy registerd in wordpress but i have to call it (am i right?) so in my child theme functions.php,i added this:

   function my_enqueue() {
   wp_enqueue_script( 'jquery-ui-draggable' );
   }
   add_action( 'wp_enqueue_scripts', 'my_enqueue' );

   ?>

3 .the script itself is only one line so i included it directly in the my child theme page.php like this

       <?php if ( is_page(291) ) : ?>   
       <script>
    jQuery( ".easingsliderlite-icon" ).draggable({ revert: true }); 
        </script>
       <?php endif; ?>

now what happens is that this line of script is loaded before the UI jquery library,when I look at the page in the browser (source code) the UI library is at the buttom of the page meaning its probebly loading after my script

so the script doesnt work:(

4 i know you can create dependencies but only with wp-enqueue and only in function.php not for single line of script in page.php (am i correct?) ,

share|improve this question

2 Answers 2

Enqueue your script instead of putting it in your template, you can enqueue your code as is, or put your code in an actual file.

The benefit of doing this is you gain control over output, as you can see there is a $priority parameter for add_action.

add_action( $hook, $function_to_add, $priority, $accepted_args );

Futhermore wp_enqueue_script comes with two parameters which can alter output, which are $deps and $in_footer.

wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );

So with the above 3 settings you can surely change the way the scripts load.

http://codex.wordpress.org/Function_Reference/wp_enqueue_script http://codex.wordpress.org/Function_Reference/add_action

share|improve this answer

When you use wp_enqueue_script you can tell wordpress what the script depends on so the loading can be done in the right order.

What you need to do here is something like (didn't try it):

wp_enqueue_script( 'jquery-ui-draggable', false, array('jquery-core','jquery-ui-core' ));

You don't have to put this in functions.php, you should be able to put it in the top of page.php (before wp_head()). Then you must add your oneliner of code somewhere after wp_head.

Now when I wrote this I suspect that the problem with your code is not the dependencies but maybe you put your oneliner too early in the code. You can put it in the bottom of page.php.

Also, you can make a specific template for this page. Just copy page.php and call it page-291.php (or you can call it page-{slug}.php)

share|improve this answer

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.