0

a slider plugin puts its javascript “right before the closing body-tag” using an add_action() hook like this:

protected static function addAction($action,$eventFunction){
    add_action( $action, array(self::$t, $eventFunction) );         
}

-

UniteBaseClassRev::addAction('wp_footer', 'putJavascript');

-

public function putJavascript(){
    $urlPlugin = UniteBaseClassRev::$url_plugin."rs-plugin/";
    ?>
    <script type='text/javascript' src='<?php echo $urlPlugin?>js/jquery.themepunch.plugins.min.js?rev=<?php echo GlobalsRevSlider::SLIDER_REVISION; ?>'></script>
    <script type='text/javascript' src='<?php echo $urlPlugin?>js/jquery.themepunch.revolution.min.js?rev=<?php echo  GlobalsRevSlider::SLIDER_REVISION; ?>'></script>
    <?php
}

the theme I use also uses add_action() to unregister the wordpress jquery and use its own:

function FoundationPress_scripts() {
// deregister the jquery version bundled with wordpress
wp_deregister_script( 'jquery' );
// enqueue modernizr, jquery and foundation
wp_enqueue_script( 'modernizr', get_template_directory_uri() . '/js/modernizr/modernizr.min.js', array(), '1.0.0', false );
wp_enqueue_script( 'jquery', get_template_directory_uri() . '/js/jquery/jquery.min.js', array(), '1.0.0', true );
wp_enqueue_script( 'foundation', get_template_directory_uri() . '/js/app.js', array('jquery'), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'FoundationPress_scripts' );

now what happens is that the slider scripts are loaded before the jquery is loaded and therefore do not work:

devtools

so my question is how I can change the order of the add_action() hooks to be fired. any other solution to solve this is fine.

2
  • 1
    There's the "Dependency API" for that. Stuff like wp_register_script() and wp_enqueue_script(). Take a look at wp-enqueue-script for examples.
    – kaiser
    Mar 11, 2014 at 17:30
  • 1
    Themes should never deregister core-bundled jQuery. I recommend using a different Theme. Mar 11, 2014 at 17:45

1 Answer 1

2

I think the real answer here, is to have the plugin author load scripts properly using wp_enqueue_script().

Or, you could change the theme enqueue code to output jquery to the header by changing to this (not great for performance reasons, but relatively simple):

wp_enqueue_script( 'jquery', get_template_directory_uri() . '/js/jquery/jquery.min.js', array(), '1.0.0', false );

Or, you could rewrite the plugin code so that it uses the enqueue process.

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.