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?
3 Answers
Reset to default 3Here'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' );