最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

tinymce - Should the WP post editor B (bold) button be inserting a <b> tag instead of <strong> in HT

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Nov 12, 2014 at 2:59 Milo 79k4 gold badges128 silver badges168 bronze badges asked Nov 11, 2014 at 20:47 buckthornbuckthorn 1511 silver badge5 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 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.

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/

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' );
发布评论

评论列表(0)

  1. 暂无评论