TinyMCE: ajout de CSS au menu déroulant du format
2 réponses
- votes
-
- 2015-07-03
Selon cette réponse ,la clépourfaire apparaître les styles dans la liste déroulanteest de
unset($settings['preview_styles']);
add_filter( 'tiny_mce_before_init', 'fb_mce_before_init' ); function fb_mce_before_init( $settings ) { // customize as desired // unset the preview styles unset($settings['preview_styles']);` return $settings; }
Per this answer, the key to getting the styles to appear in the dropdown is to
unset($settings['preview_styles']);
add_filter( 'tiny_mce_before_init', 'fb_mce_before_init' ); function fb_mce_before_init( $settings ) { // customize as desired // unset the preview styles unset($settings['preview_styles']);` return $settings; }
-
- 2015-01-30
Très utileet mercipour lespointeurs
defaultstyles
. J'aitrouvé que lafusion destableauxne fonctionnaitpasjusqu'à la conversion de ces optionspar défauten JSON valide (JavaScriptnon valide). Ci-dessouspermet d'ajouter lemenu déroulant de WordPresstinymce au lieu de remplacerOptionspar défaut (JSON):
$defaults = '[{ "title": "Headers", "items": [ { "title": "Header 1", "format": "h1" }, { "title": "Header 2", "format": "h2" }, { "title": "Header 3", "format": "h3" }, { "title": "Header 4", "format": "h4" }, { "title": "Header 5", "format": "h5" }, { "title": "Header 6", "format": "h6" } ] }, { "title": "Inline", "items": [ { "title": "Bold", "icon": "bold", "format": "bold" }, { "title": "Italic", "icon": "italic", "format": "italic" }, { "title": "Underline", "icon": "underline", "format": "underline" }, { "title": "Strikethrough", "icon": "strikethrough", "format": "strikethrough" }, { "title": "Superscript", "icon": "superscript", "format": "superscript" }, { "title": "Subscript", "icon": "subscript", "format": "subscript" }, { "title": "Code", "icon": "code", "format": "code" } ] }, { "title": "Blocks", "items": [ { "title": "Paragraph", "format": "p" }, { "title": "Blockquote", "format": "blockquote" }, { "title": "Div", "format": "div" }, { "title": "Pre", "format": "pre" } ] }, { "title": "Alignment", "items": [ { "title": "Left", "icon": "alignleft", "format": "alignleft" }, { "title": "Center", "icon": "aligncenter", "format": "aligncenter" }, { "title": "Right", "icon": "alignright", "format": "alignright" }, { "title": "Justify", "icon": "alignjustify", "format": "alignjustify" } ] } ]';
Dansfunctions.php,retournez le hachage d'optionsplus larges:
add_filter( 'tiny_mce_before_init', 'fb_mce_before_init' ); function fb_mce_before_init( $settings ) { $style_formats = array( //.... $settings['style_formats'] = json_encode( array_merge( json_decode($defaults), $style_formats ) ); return $settings; }
Very helpful and thanks for
defaultstyles
pointers. I found merging arrays wasn't working until converting those default options to valid JSON (not valid JavaScript). Below allows appending the WordPress tinymce's drop-down instead of replacingDefault options (JSON):
$defaults = '[{ "title": "Headers", "items": [ { "title": "Header 1", "format": "h1" }, { "title": "Header 2", "format": "h2" }, { "title": "Header 3", "format": "h3" }, { "title": "Header 4", "format": "h4" }, { "title": "Header 5", "format": "h5" }, { "title": "Header 6", "format": "h6" } ] }, { "title": "Inline", "items": [ { "title": "Bold", "icon": "bold", "format": "bold" }, { "title": "Italic", "icon": "italic", "format": "italic" }, { "title": "Underline", "icon": "underline", "format": "underline" }, { "title": "Strikethrough", "icon": "strikethrough", "format": "strikethrough" }, { "title": "Superscript", "icon": "superscript", "format": "superscript" }, { "title": "Subscript", "icon": "subscript", "format": "subscript" }, { "title": "Code", "icon": "code", "format": "code" } ] }, { "title": "Blocks", "items": [ { "title": "Paragraph", "format": "p" }, { "title": "Blockquote", "format": "blockquote" }, { "title": "Div", "format": "div" }, { "title": "Pre", "format": "pre" } ] }, { "title": "Alignment", "items": [ { "title": "Left", "icon": "alignleft", "format": "alignleft" }, { "title": "Center", "icon": "aligncenter", "format": "aligncenter" }, { "title": "Right", "icon": "alignright", "format": "alignright" }, { "title": "Justify", "icon": "alignjustify", "format": "alignjustify" } ] } ]';
In functions.php return the larger options hash:
add_filter( 'tiny_mce_before_init', 'fb_mce_before_init' ); function fb_mce_before_init( $settings ) { $style_formats = array( //.... $settings['style_formats'] = json_encode( array_merge( json_decode($defaults), $style_formats ) ); return $settings; }
-
Remarque: Les stylespar défautpeuvent être ajoutés à la liste déroulante desformatsen ajoutant `$ settings ['style_formats_merge']=true;` dans »fb_mce_before_init ()«.Note: The default styles can be added to the formats dropdown by adding `$settings['style_formats_merge'] = true;` into »fb_mce_before_init()«.
- 0
- 2015-07-30
- Nicolai
J'ai ajouté avec succès unefeuille de style TinyMCE à l'aide de add_editor_style () afin depouvoirprévisualiser les styles dans le corps de l'éditeur TinyMCE.
Cependant,ai-je raison de supposer que lafonction add_editor_style ()ne peut accéder au style quepour le corps de l'éditeur?
Si c'est le cas,y a-t-il une autreméthode oufonction queje peux utiliserpour accéder également au style de la liste déroulante Format TinyMCE?