WPUtils (now in its first version) is a jQuery utility to hook into a Wordpress site. I've created this utility to help developers with attaching actions to specific Wordpress sections. For that reason, WPUtils features several helper functions that check if we're on a specific Wordpress page. Let's see the details.
WPUtils is an object that lives within the jQuery's namespace:
/** WPUtils: A generic jQuery utility for Wordpress
*
* @version 1.0
* @author Gabriele Romanato <gabriele.romanato@gmail.com>
* @requires jQuery 1.5+
* @license This work is public domain
*/
(function($) {
$.WPUtils = {
/** Check if a document is the home page
* @return Boolean
*/
isHome: function() {
if(!$('body').hasClass('home')) {
return false;
}
return true;
},
/** Check if a document is a Wordpress page
* @return Boolean
*/
isPage: function() {
if(!$('body').hasClass('page')) {
return false;
}
return true;
},
/** Check if a document is a single post page
* @return Boolean
*/
isSingle: function() {
if(!$('body').hasClass('single')) {
return false;
}
return true;
},
/** Check if a document is an archive page
* @return Boolean
*/
isArchive: function() {
if(!$('body').hasClass('archive')) {
return false;
}
return true;
},
/** Check if a document is a tag page
* @return Boolean
*/
isTag: function() {
if(!$('body').hasClass('tag')) {
return false;
}
return true;
},
/** Binds a callback function to the ready() event
* of the document object
* @return void
*/
load: function(callback) {
$(document).bind('ready', callback);
}
};
})(jQuery);
It also features a simple load() method that binds a callback function to the DOM ready() event. Example:
$.WPUtils.load(function() {
alert($.WPUtils.isHome()); // true
});
I need your suggestions to expand it and make it better.