Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End jQuery Plugin Files won’t ever work!!

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #40552
    Targyro
    Member

    Hi guys,

    Thanks in advance for any help anyone will give me!

    have a good understanding of WordPress and I have been able to create my own custom theme from scratch and manipulate it the way I want to.

    The next step for me was to implement some cool jQuery plugins to extend my abilities!

    The thing is I’ve tried every single tutorial out there, read everyting about wp_enqueue and wp_register etc. etc. !

    The good news: I can see both jQuery and any other custom jQuery script I use, loading in the source of a browser in the header.

    The bad news: Although the custom script is being loaded it isn’t working.

    Here is some example code from my theme’s functions.php :

    (Oh before that: I am using “Use Goggle Libraries” WordPress Plugin to load jQuery, so I’m not queueing it again in the functions.php).

    function custom_scripts_load()
    {

    // Register the script like this for a theme:
    wp_register_script( ‘custom-script’, get_bloginfo(‘template_directory’) . “/js/custom-script.js” );
    // For either a plugin or a theme, you can then enqueue the script:
    wp_enqueue_script( ‘custom-script’ );
    }
    add_action( ‘wp_enqueue_scripts’, ‘custom_scripts_load’ );

    And the simplest of javascript just to test it in my custom-script.js file :

    $(function)() {
    $(“body”).css(“background”,”blue”);

    }

    So to recap: I can see botH , jQuery and custom-script.js loading in the Source

    BUT

    Nothing ever really happens.

    Any help would be extremely appreciated!

    Thanks once again in advance.

    #113102
    Senff
    Participant

    You have a closing bracket misplaced. Try this:

    $(function() { $(“body”).css(“background”,”blue”);
    });

    Or perhaps even better:

    $(document).ready(function(){
    $(“body”).css(“background”,”blue”);
    });

    #113103
    Targyro
    Member

    Hey Senff,

    Thanks for replying.

    Tried it and I get an error:

    ‘undefined’ is not a function (evaluating’$(document)’)

    #113105
    Targyro
    Member

    Don’t worry about it actually. I used this little snippet and it did work!

    (function ($) {
    $(document);
    }(jQuery));

    #113106
    Senff
    Participant

    Looks like there is a noConflict set there. You can also just do this then:

    jQuery(document).ready(function(){
    jQuery(“body”).css(“background”,”blue”);
    });

    #113525
    theplastickid
    Participant

    I often have messed up my jQuery scripts and plugins by leaving out the wp_head and wp_footer hooks. Their pretty essential.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.