Skip to content

Instantly share code, notes, and snippets.

@dirtystylus
Created September 16, 2014 20:35
Show Gist options
  • Save dirtystylus/c34987ceede16668e62f to your computer and use it in GitHub Desktop.
Save dirtystylus/c34987ceede16668e62f to your computer and use it in GitHub Desktop.
WordPress Remove Text Tab Buttons
function _remove_quicktags( $qtInit )
{
// Remove only the 'italic', 'bold', and 'block-quote' buttons
$remove_these = array('strong', 'em', 'block', 'link', 'del', 'ins', 'img', 'ul', 'ol', 'li', 'code', 'more', 'close');
// Convert string to array
$buttons = explode(',', $qtInit['buttons']);
// Loop over items to remove and unset them from the buttons
for( $i=0; $i < count($remove_these); $i++ )
{
if( ($key = array_search($remove_these[$i], $buttons)) !== false)
unset($buttons[$key]);
}
// Convert new buttons array back into a comma-separated string
$qtInit['buttons'] = implode(',', $buttons);
return $qtInit;
}
add_filter('quicktags_settings', '_remove_quicktags', 10, 1);
@cowgill
Copy link

cowgill commented Apr 15, 2015

Thanks for sharing your code. Here's a simpler way without the loop. 😄

/**
 * Remove certain buttons from text editor and wp_editor() functions
 *
 * @return array
 */
function appthemes_editor_buttons( $qtInit ) {

  // available buttons
  // strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,dfw

  $remove = array( 'more', 'close' );

  // put comma separated buttons into array
  $buttons = explode( ',', $qtInit['buttons'] );

  // spit out the buttons to keep
  $buttons = array_diff( $buttons, $remove );

  // put back into comma separated list
  $qtInit['buttons'] = implode( ',', $buttons );

  return $qtInit;
}
add_filter( 'quicktags_settings', 'appthemes_editor_buttons' );

@dirtystylus
Copy link
Author

@cowgill Thanks for that!

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