2

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();
}
4
  • 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, 2012 at 6:27
  • well the h1 is not being applied to the highlighted item when selected from the drop down. Oct 26, 2012 at 21:06
  • What does the HTML view look like after you apply h1 to highlighted item?
    – Miha Rekar
    Oct 27, 2012 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, 2013 at 22:14

1 Answer 1

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;
}
1
  • oops I did actually have that in my code, I forgot to copy and paste it above. Oct 26, 2012 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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