Despite the fact that more and more websites are moving towards HTML5 standard because of numerous advanced features, WordPress seems to be naive enough to stick around xHTML. Since I personally don’t like this idea, I am taking things in my own hand and follow the HTML5 standard whenever it’s possible.
Generally the_content function that retrieves your blog post seems to get <br/> (self closing line break) tag automatically from wpautop function. Since HTML5 uses <br> instead of <br/>, I had to figure out a way to resolve this issue.
<?php
add_filter('the_content','html5_line_break_tag', 20);
function html5_line_break_tag($content) {
return str_replace('<br />','<br>', $content);
}
?>
This idea is fairly simple. Filter the post content and replace all the <br/> tag with <br> and then show the content. To do this, I simply created a function and used str_replace PHP function to replace all <br/> with <br> and hooked it up with the_content function.
All you need to do now is to copy and paste the above snippet on your theme’s functions.php age and update it. That’s all.
Comment
Leave a Reply