Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom styles for Wordpress TinyMCE
    primarykey
    data
    text
    <p>I've read several tutorials for adding custom styles to the WYSIWYG (TinyMCE) editor. None of them seem to work in the newest version(s) of Wordpress. I'm using v3.3.2. The <a href="http://codex.wordpress.org/TinyMCE_Custom_Buttons" rel="nofollow">instructions from the codex</a> work, but in a limited way...</p> <p>NOTE: To be 100% clear, I'm trying to add a "Styles" dropdown which the author can use to apply my custom styles to the text. (Please don't confuse my question with how to style the editor its self, using editor-style.css... )</p> <p>I managed to get the code working, but only using the commented-out line in <code>my_mce_before_init()</code>. The problem with this version is that it adds the class with a generic <code>&lt;span&gt;</code>. I'm trying to use the more powerful version of the code (as shown below), but something isn't quite right. The styles drop-down box appears, but it's blank. If I click it the first item is says "Styles" but does nothing. I suspect there's something off about my array. Hopefully someone more knowledgeable than me can set me straight.</p> <p>Here's the relevant code in my theme's functions.php...</p> <p>Here's how I add the button:</p> <pre><code>// Add the Style selectbox to the second row of MCE buttons function my_mce_buttons_2($buttons) { array_unshift($buttons, 'styleselect'); return $buttons; } add_filter('mce_buttons_2', 'my_mce_buttons_2'); </code></pre> <p>Here's how I add the styles (it works when I uncomment the ):</p> <pre><code>//Define the actual styles that will be in the box function my_mce_before_init($init_array) { // add classes using a ; separated values //$init_array['theme_advanced_styles'] = "Section Head=section-head;Sub Section Head=sub-section-head"; $temp_array['theme_advanced_styles'] = array( array( 'title' =&gt; 'Section Head', 'block' =&gt; 'h3', 'classes' =&gt; 'section-head' ), array( 'title' =&gt; 'Sub Section Head', 'block' =&gt; 'h4', 'classes' =&gt; 'sub-section-head' ) ); $styles_array = json_encode( $temp_array['theme_advanced_styles'] ); // THIS IS THE PROBLEM !!!! READ BELOW $init_array['theme_advanced_styles'] = $styles_array; return $init_array; } add_filter('tiny_mce_before_init', 'my_mce_before_init'); </code></pre> <p><strong>UPDATE: I figured it out (see my answer below). Before you scroll down, notice in the code above, <code>theme_advanced_styles</code> is the wrong key. It should be <code>style_formats</code> when defining the custom styles in the way that I'm doing. I suspect this is a common mistake.</strong> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload