-
Book Overview & Buying
-
Table Of Contents
WordPress 3.0 jQuery
We'll discover that compared to WordPress themes and plugins, jQuery plugins are actually not that complex.
To set up a jQuery plugin, you need to follow jQuery's plugin construct. The basic construct consists of setting up a jQuery function for your plugin as follows. Note the bold .fn added to the jQuery object. This is what makes your function a jQuery function.
jQuery.fn.yourFunctionName = function() {
//code
};
Within that, it's best practice to then add a return this.each(function(){...}); so that your function will run through each item in the jQuery selector.
jQuery.fn.yourFunctionName = function() {
return this.each(function(){
//code
});
};
Unlike WordPress, which requires specifically formatted comments in theme CSS stylesheets and in plugin headers, jQuery does not require a commented-out header, but it's nice to add one up top.
/*
You can name the plugin
Give some information about it
Share some details about yourself
Maybe offer contact info for...
Change the font size
Change margin width
Change background colour