Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using the following code to add style drop downs the mce toolbar, I want to be able to add a h1 element with the drop down but my code isnt working, I have tried a couple of different ways but it doesnt work, I got this code form here

add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );
function my_mce_buttons_2( $buttons ) {
    array_unshift( $buttons, 'styleselect' );
    return $buttons;
}
//mce custom classes
add_filter( 'tiny_mce_before_init', 'my_mce_before_init' );

function my_mce_before_init( $settings ) {

    $style_formats = array(
        array(
            'title' => 'Button',
            'selector' => 'h1',
            'classes' => 'button'
        ),
        array(
            'title' => 'h1',
            'block' => 'h1',
            'classes' => 'superHead',
            'wrapper' => true
        ),
        array(
            'title' => 'Bold Brown',
            'inline' => 'span',
            'styles' => array(
                'color' => '#481e07',
                'fontWeight' => 'bold'
            )
        ),
        array(
            'title' => 'Header',
            'inline' => 'span',
            'styles' => array(
                'font-size' => '24px'
            )
        )
    );

    $settings['style_formats'] = json_encode( $style_formats );

    return $settings;

}

//mse custome classes
add_action( 'admin_init', 'add_my_editor_style' );

function add_my_editor_style() {
    add_editor_style();
}
share|improve this question
1  
"my code isnt working" How it isn't working? Do you get an error or nothing happens or something else happens? Please elaborate. –  Miha Rekar Oct 26 '12 at 6:27
    
well the h1 is not being applied to the highlighted item when selected from the drop down. –  Anders Kitson Oct 26 '12 at 21:06
    
What does the HTML view look like after you apply h1 to highlighted item? –  Miha Rekar Oct 27 '12 at 7:05
    
I'm experiencing the same problem. @MihaRekar If I check HTML there's nothing wrapping the selected portion of text. –  INT Jan 6 '13 at 22:14

1 Answer 1

Based on the tutorial you are missing the whole first step:

add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );

function my_mce_buttons_2( $buttons ) {
    array_unshift( $buttons, 'styleselect' );
    return $buttons;
}
share|improve this answer
    
oops I did actually have that in my code, I forgot to copy and paste it above. –  Anders Kitson Oct 26 '12 at 21:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.