- This topic is empty.
-
AuthorPosts
-
November 1, 2012 at 7:06 am #40552TargyroMember
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.
November 1, 2012 at 9:20 am #113102SenffParticipantYou have a closing bracket misplaced. Try this:
$(function() { $(“body”).css(“background”,”blue”);
});Or perhaps even better:
$(document).ready(function(){
$(“body”).css(“background”,”blue”);
});November 1, 2012 at 9:28 am #113103TargyroMemberHey Senff,
Thanks for replying.
Tried it and I get an error:
‘undefined’ is not a function (evaluating’$(document)’)
November 1, 2012 at 9:34 am #113105TargyroMemberDon’t worry about it actually. I used this little snippet and it did work!
(function ($) {
$(document);
}(jQuery));November 1, 2012 at 9:37 am #113106SenffParticipantLooks like there is a noConflict set there. You can also just do this then:
jQuery(document).ready(function(){
jQuery(“body”).css(“background”,”blue”);
});November 6, 2012 at 5:17 pm #113525theplastickidParticipantI often have messed up my jQuery scripts and plugins by leaving out the wp_head and wp_footer hooks. Their pretty essential.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.