Skip to content

Instantly share code, notes, and snippets.

@webbyworks
Last active December 21, 2015 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webbyworks/6246863 to your computer and use it in GitHub Desktop.
Save webbyworks/6246863 to your computer and use it in GitHub Desktop.
Want to add icons next to Wordpress Text/HTML widget headers? Here's a simple jQuery function that does just that. It assumes that within the widget you have already defined the icon element using the CSS class selector of ".icon-widget" in the body of the HTML widget. See this page for an example: http://www.webbyworks.com.au/95/adding-icons-to…
(function($) {
// move icons in sidebar to be in front of their header
if ( $('#sidebar').length > 0 ) {
// get all widget titles and loop through each
$("#sidebar h4.widget-title").each( function(index) {
// get the sibling textwidget > span
var sibling = $(this).parent().find(".icon-widget");
$(this).before( sibling );
});
}
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment