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.

In the Wordpress control panel, when writing a new post, I would like to disable the Header 1 and Header 2 from the text formatting combobox, because I already use them on my theme (h1 for blog name and h2 for post titles), and would like to keep all headers inside a post with h3 or higher. Is that possible?

It doesn't matter for the case if the code can be edited in the HTML view. Also, I don't want to edit Wordpress internal files, so a hack for functions.php or a plugin would be great for this task, in order to preserve this change across future updates.

Thank you!

share|improve this question

2 Answers 2

up vote 8 down vote accepted

you can change lots of things about the tinyMCE editor at the tiny_mce_before_init filter.

http://codex.wordpress.org/TinyMCE_Custom_Buttons

the following will restrict your blockformats to p,h3,h4 and blockquote

function wpa_45815($arr){
    $arr['theme_advanced_blockformats'] = 'p,h3,h4,blockquote';
    return $arr;
  }
add_filter('tiny_mce_before_init', 'wpa_45815');

EDIT for WordPress 3.9 see link

function wpa_45815($arr){
    $arr['block_formats'] = 'Paragraph=p;Heading 3=h3;Heading 4=h4';
    return $arr;
  }
add_filter('tiny_mce_before_init', 'wpa_45815');
share|improve this answer
1  
Perfect! Didn't know I could control every aspect of the visual editor using a filter. Thanks for the tip, and for the reference link! –  André Mar 16 '12 at 15:12
    
This simply works. I love it. –  Ardee Aram Apr 14 '13 at 15:21
1  
The syntax has changed as of wp 3.9 (probably). Now it should be $init['block_formats'] = "Paragraph=p;Heading 3=h3;Heading 4=h4";. See wordpress.org/support/topic/… –  Andreas Hultgren Jun 2 at 13:36

This is a quick and dirty solution but it may work if your objective is to disable H1 and H2.

Add this code to your functions.php file

function custom_css() {
echo '<style type="text/css">
       #menu_content_content_formatselect_menu #mce_9, #menu_content_content_formatselect_menu #mce_10 {display:none;}
     </style>';
}

add_action('admin_head', 'custom_css');

Heading 1 and Heading 2 should be hidden now.

share|improve this answer
    
Your solution is also very good for what I want, it works. Just as a note, the mce_<number> can be different for each locale (in my case, Portuguese, the numbers were the 4 and 5 for h1 and h2 respectively). Thanks for your help! –  André Mar 16 '12 at 15:14

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.