Skip to content

Instantly share code, notes, and snippets.

@xymox12
Created November 21, 2013 23:02
Show Gist options
  • Save xymox12/7591425 to your computer and use it in GitHub Desktop.
Save xymox12/7591425 to your computer and use it in GitHub Desktop.
Modify multiple tinymce's on the same Advanced Custom Field post type (in this case post_type == 'fellow')
/* Tiny MCE Modifications */
function emy_refresh_mce($ver) {
++$ver; // or $ver .= 3; or ++$ver; etc.
return $ver;
}
add_filter('tiny_mce_version', 'emy_refresh_mce');
function myformatTinyMCE($in) {
$style_formats = array(
array(
'title' => 'First paragraph',
'selector' => 'p',
'classes' => 'standFirst'
)
);
global $post_type;
// var_dump($post_type);
if( 'fellow' == $post_type ) {
$in['theme_advanced_blockformats'] = 'p,h3,h4,h5,h6';
} else {
$in['theme_advanced_buttons1_add'] = 'styleselect';
$in['style_formats'] = json_encode($style_formats);
$in['theme_advanced_blockformats'] = 'p,h2,h3,h4,h5,h6';
}
return $in;
}
add_filter('tiny_mce_before_init', 'myformatTinyMCE');
/* ACF */
add_filter('acf/fields/wysiwyg/toolbars', 'my_toolbars');
function my_toolbars($toolbars) {
// Uncomment to view format of $toolbars
// echo '< pre >';
// print_r($toolbars);
// echo '< /pre >';
// die;
// Add a new toolbar called "Very Simple"
// - this toolbar has only 1 row of buttons
$toolbars['Very Simple'] = array();
$toolbars['Simple and Headers'] = array();
// var_dump($toolbars['Full']);
$toolbars['Very Simple'][1] = array('bold', 'italic', 'bullist', 'numlist', 'link', 'unlink','removeformat');
$toolbars['Simple and Headers'][1] = array('formatselect', 'bold', 'italic', 'bullist', 'numlist', 'link', 'unlink', 'sub', 'sup','|','removeformat');
// Edit the "Full" toolbar and remove 'code'
// - delet from array code from http://stackoverflow.com/questions/7225070/php-array-delete-by-value-not-key
if (($key = array_search('code', $toolbars['Full'][2])) !== false) {
unset($toolbars['Full'][2][$key]);
}
// remove the 'Basic' toolbar completely
// unset( $toolbars['Baisc' ] );
// return $toolbars - IMPORTANT!
return $toolbars;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment