Sometimes the title of an article is too long due to the theme and will be displayed in two lines, which looks a bit unsightly. Therefore, at this time, it is necessary to control the title of the article to a certain length so that it will not be displayed in two lines. The controlled The method is quite simple, you only need to replace the original title output code of the WordPress blog. The following blog post will introduce how to control the length of the WordPress blog title.
Control WordPress blog title length:
WordPress blogs generally use <?php the_title(); ?> to output the article title. This code is the complete output display of the title. To control the length of the title, just replace it with the following code:
<?php echo mb_strimwidth(get_the_title(), 0, 40, '...'); ?>
The values 0 and 40 represent the 0th to 40th bits of the output string. The two values can be set according to different needs.
Reminder: Using this code requires that the PHP server where the blog is located supports the MB library (the full name of the mbstring library is Multi-Byte String)
» Please indicate the source when reprinting: Blog Bar
» The address of this article: http://www.boke8.net/wordpress-control-title-length.html
Thanks for the blog post