WordPress.org

Ready to get started?Download WordPress

Forums

Fixing jQuery and posibli loading newest version (9 posts)

  1. Hooch
    Member
    Posted 1 year ago #

    Hello all.

    I'm not pro PHP programmer, mainly C++ and C#. I also know a bit (even more) of JS and jQuery and I would love to have it working on my WP page.

    I have problem with it. I have some plugins that depend on jQuery but are not working. For example that slideshow on homepage that is not sliding (vSlider). But smooth scrolling is working.

    I would like to fix my WP page to load jQuery only once and I wuld like it to be the newest version.

    Here is my page: http://www.uksgrot.com

  2. linux4me2
    Member
    Posted 1 year ago #

    I looked at your site and your problems are probably because you are loading jQuery twice--and two different versions--as you suspected.

    The proper way to load jQuery in WordPress, and to add additional custom javascript files, is described in the Codex here.

    If the javascript for vlsider doesn't load automatically, what you'd want to do is create a child theme so that your changes are not over-written when you upgrade your theme, create a functions.php file in your child theme folder, and add the following to it:

    <?php
    function add_vslider_js () {
    	wp_enqueue_script('vslider', plugins_uri() . '/js/vslider.js', array('jquery'));
    }
    add_action('wp_enqueue_scripts', 'add_vslider_js');
    ?>

    If you hardcoded the following, you'll need to remove it from your header:

    <!-- Code Inserter module -->
    <script src="http://www.hl2.boo.pl/uksgrot/jquery-1.9.0.min.js"></script>
    <script src="http://vibethemes.com/wp-content/plugins/vslider/js/vslider.js"></script>
    <!-- /Code Inserter module -->

    If vslider added the code above, you'll have to take a bit different approach.

  3. Hooch
    Member
    Posted 1 year ago #

    Ok.
    I removed that hardcoded stuff.
    I'm trying to create my template child but I can't activate it.
    I'm getting message in template selection that my child template is not complete. That is has missing teplate files.

    Here is my style.css from child template:

    /*
    Theme Name: LightWord Child
    Theme URI: http://www.uksgrot.com
    Description: UKS Grot Edition of LightWord theme
    Author: Andrei Luca & Maciej Kusnierz
    Template: lightword
    Version: 0.0.0.1
    */
    
    @import url("../lightword/style.css");

    And to functions.php in child template I added:

    <?php
    
    function add_jquery() {
        wp_enqueue_script('jquery', 'www.hl2.boo.pl/uksgrot/jquery-1.9.0.min.js');
    }    
    
    add_action('wp_enqueue_scripts', 'add_jquery'); // For use on the Front end (ie. Theme)
    
    function add_vslider_js () {
    	wp_enqueue_script('vslider', plugins_uri() . '/js/vslider/vslider.js', array('jquery'));
    }
    
    add_action('wp_enqueue_scripts', 'add_vslider_js');
    ?>

    It is not working now because I can't load that child template at all.

  4. linux4me2
    Member
    Posted 1 year ago #

    Hmmm... I don't see anything wrong with the style.css you created. Did you save it as:
    /wp-content/themes/lightword-child/style.css
    or something similar? Usually, that message is because WordPress is unable to locate the style.css.

    That functions.php isn't right. You don't need to explicitly load jQuery because it is listed in the array of dependencies for vslider.js by its registered script handle "jquery." So your functions.php should look just like the one I gave you. All you need is the following:

    <?php
      function add_vslider_js () {
    	wp_enqueue_script('vslider', plugins_uri() . '/js/vslider/vslider.js', array('jquery'));
    }
    
    add_action('wp_enqueue_scripts', 'add_vslider_js');
    ?>

    jQuery will be loaded if the theme and no other plugin has already required it, but it won't be loaded twice.

  5. Hooch
    Member
    Posted 1 year ago #

    Yes. I saved it as style.css in Thames child directory.
    Where is jquery loaded from then?

  6. linux4me2
    Member
    Posted 1 year ago #

    That's strange. Did you create the style.css with a text-only editor and not with a word processor? I can't think of any other reason it would be giving you that error. Style.css is the only required file as far as I know.

    The version that comes with WordPress is loaded. Usually, that's the latest stable version tested with WordPress. It's in /wp-includes/js/jquery. With WP 3.5, the current version is 1.8.3.

  7. Hooch
    Member
    Posted 1 year ago #

    Yes. In notepadd++ witch .css extension. I'm programmer. I know that.
    Ok. I will ignore that child style thing. How to fix it so that plugins are not loading jquery multiple times? SHould I juest edit plugins files directly? But it will not survive updates? And what if plugins uses $ instead of jquery? I heard there is some problem with that too.

  8. linux4me2
    Member
    Posted 1 year ago #

    If you figure out why the child theme is giving you that error, please post. I can't see that there is anything wrong with your child style.css, and I'd like to know what it was in case I have that problem in the future.

    WordPress themes and plugins are supposed to load jQuery via wp_enqueue_script too, so jQuery should only be loaded once regardless of how many plugins you have that require it, unless you're running some plugins that weren't built in accordance with the WordPress guidelines or haven't been kept up-to-date.

    Plugins are supposed to use jQuery no-conflict mode now too I believe, so again, if they're current, they shouldn't be using $. That doesn't mean you won't have some that are... Before I'd re-code them myself, I'd contact the developer of the plugins and ask them about fixing them.

    If all you're going to change is your theme's functions.php, you can just keep a backup of it and if your theme is updated, merge the changes you made into the new version. Since you're not using a default theme, you will choose when to update your theme, so this will be easier, though still not as easy as running a child theme.

  9. Hooch
    Member
    Posted 1 year ago #

    I will try to fix it.
    But if you want I can give you access to ftp server.
    Contact me via msn (maciej[the dot]kusnierz[aatttat]hoooooooootmail.coooooooooom)

Topic Closed

This topic has been closed to new replies.

About this Topic