2

For the sake of my site editors, I'm trying to rename the Headings in the TinyMCE dropdown.

I looked into filtering options but came up totally empty.

I've also tried a javascript solution but haven't gotten anywhere with that.

When I run jQuery('#mce_4 a').text('Heading'); in the browser console, it works like a charm, yet when I put it into an javascript file and put it in the .load() function nothing happens. (The file itself is fine as it's running other functions already.)

If I run console.log(jQuery('#mce_4 a')); in my file, it comes up empty as if there isn't any DOM object matching that selector. The TinyMCE editor buttons are not in an iframe themselves, so that doesn't seem to be the issue either.

I would be thrilled with a PHP or JS solution.

1

I would use the hook tiny_mce_before_init :

function wpse_106063_tinymce($arr){
$arr['theme_advanced_blockformats'] = 'h1,h2,h3,h4';

$style_formats = array(
    array('title' => 'title', 'block' => 'h1')),
// etc
);
$arr['style_formats'] = json_encode( $style_formats );


return $arr;
}
add_filter('tiny_mce_before_init', 'wpse_106063_tinymce');

Hope it helps.

EDIT: add something that should work, not tested. source

  • Thanks for your answer, @JMa. That hook works great for changing what block formats are shown (and I'm doing that), but I don't think it can change the labels used for the block formats (e.g. "Heading 2") which is what I'm trying to do. – mrwweb Jul 10 '13 at 22:10
  • I've edited code – JMau Jul 10 '13 at 22:25
  • Hmmm. That works to add an h1 to the styleselect (separate from formatselect). I'm already using the styleselect for inline styles so it would be nice to leave the block formats in the formatselect drop down since those concepts (styles vs html block elements) are separate. – mrwweb Jul 10 '13 at 22:32
  • I guess it should be done in js – JMau Jul 10 '13 at 22:42
  • If only I could figure out how! Thanks for your help though. Much appreciated. – mrwweb Jul 10 '13 at 23:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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