2

Using WP 4.0. I thought that the html5 schema was supposed to be turned on by default. That would mean that clicking the B (Bold) button would generate a <b> tag, rather than a <strong> tag (which has a different semantic meaning). The same question goes for clicking the I button to get an <i> tag instead of <em>. How can I get the editor to do this?

3

Here's what I came up with. So far it doesn't seem to have broken anything:

add_filter('tiny_mce_before_init', 'modify_formats');

function modify_formats($settings){
   $formats = array(
     'bold' => array('inline' => 'b'),
     'italic' => array('inline' => 'i')
    );
    $settings['formats'] = json_encode( $formats );
    return $settings;
}

One could easily have used plus a class here, but given the changes in the spec under html5, and seem acceptable for most situations. (I don't think that the case to transform these from presentational to structural tags is terribly persuasive, but probably not worth arguing about at this point). Anyone who wants and should probably add the necessary buttons and apply them in the appropriate places.

| improve this answer | |
0

Yes, you can do it by changing in TinyMCE Editor formats as:

tinymce.init({
  selector: 'textarea',
  formats: {
    // Changes the default format for the bold button to produce a span with a bold class
    bold: { inline: 'b', classes: 'bold' }
  }
});

Content formatting options in TinyMCE Editor

If you are on WordPress then this article will be helpful for you https://tfrommen.de/using-custom-formats-in-tinymce/

| improve this answer | |
-1

The i and b tags are perfectly valid HTML(5).

Otherwise ( untested, only on output thus saved to DB as a b tag still ) :

function change_b_to_strong($content){
    str_replace('<b>', '<strong>', $content);
    str_replace('</b>', '</strong>', $content);
    return $content;
}

add_filter( 'the_content', 'change_b_to_strong' );
| improve this answer | |
  • 1
    Thanks, but I am only asking about having the bold button generate a <b> tag, and the I button an <i> tag. I don't want <strong> or <em> unless the semantics call for them. – buckthorn Nov 12 '14 at 2:05

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.