Skip to content

Instantly share code, notes, and snippets.

@daronspence
Created September 21, 2015 21:44
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 daronspence/a67a2e3ad6b203a517a6 to your computer and use it in GitHub Desktop.
Save daronspence/a67a2e3ad6b203a517a6 to your computer and use it in GitHub Desktop.
Custom button for WordPress post editor
<?php
// Callback function to insert 'styleselect' into the $buttons array
function prefix_mce_buttons( $buttons ) {
array_unshift( $buttons, 'styleselect' );
//var_dump($buttons);
return $buttons;
}
// Register our callback to the appropriate filter
// _2 places the new button on the second line
add_filter('mce_buttons_2', 'prefix_mce_buttons');
// Callback function to filter the MCE settings
function prefix_mce_before_init_insert_formats( $init_array ) {
// Define the style_formats array
$style_formats = array(
// Each array child is a format with it's own settings
array(
'title' => 'Button',
'selector' => 'a',
'classes' => 'button',
// font awesome must be available in the admin area to see the icon
'icon' => ' fa fa-hand-pointer-o'
),
);
// Insert the array, JSON ENCODED, into 'style_formats'
$init_array['style_formats'] = json_encode( $style_formats );
return $init_array;
}
// Attach callback to 'tiny_mce_before_init'
add_filter( 'tiny_mce_before_init', 'prefix_mce_before_init_insert_formats' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment