Skip to content

Instantly share code, notes, and snippets.

@Gipetto
Created February 23, 2012 17:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gipetto/1894045 to your computer and use it in GitHub Desktop.
Save Gipetto/1894045 to your computer and use it in GitHub Desktop.
Convert all category select checkboxes in to radio buttons in the WordPress post-edit screen.
// Convert all Category input checkboxes in to radio selects
// It completely replaces the elements with new ones and transfers
// the attributes from the old element to the new.
// We can't just change the type because of, you guessed it, Internet Explorer
// Yes, sometimes a hand grenade is easier than a scalpel ;)
jQuery('form#post').find('.categorychecklist input').each(function() {
var new_input = jQuery('<input type="radio" />'),
attrLen = this.attributes.length;
for (i = 0; i < attrLen; i++) {
if (this.attributes[i].name != 'type') {
new_input.attr(this.attributes[i].name.toLowerCase(), this.attributes[i].value);
}
}
jQuery(this).replaceWith(new_input);
});
@paulthomson-me
Copy link

Hi Gipetto,

Thanks for providing this useful .js, but I'm struggling to work out where I'm meant to put the code to get it to work?

I'm using WP 3.5, any help would be greatly appreciated.

Regards,
Paul

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment