Skip to content

Instantly share code, notes, and snippets.

@DevTarakanova
Last active November 13, 2018 20:19
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 DevTarakanova/ca648881c47ee4bac1ad5e2454a701b5 to your computer and use it in GitHub Desktop.
Save DevTarakanova/ca648881c47ee4bac1ad5e2454a701b5 to your computer and use it in GitHub Desktop.
Add button to WSVC
// Callback function to insert 'styleselect' into the $buttons array
function my_mce_buttons_2( $buttons ) {
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
// Register our callback to the appropriate filter
add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );
// Callback function to filter the MCE settings
function my_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' => 'Custom button',
'selector' => 'a',
'classes' => 'custom_button',
'wrapper' => false,
),
);
// 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', 'my_mce_before_init_insert_formats' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment