如何减少WordPress帖子标题的字符长度

如何减少WordPress帖子标题的字符长度,wordpress,post,title,Wordpress,Post,Title,我想限制WordPress中帖子标题的字符 假设我发表了一篇150个字符的文章,但我只想显示120个字符。有什么办法吗?您可以在wp content/themes/your theme/header.php中编辑主题的标题。然后根据字符数更改标题: <title><?php $title = wp_title(' - ', false, 'right'); if (strlen($title) > 120) $title = substr($title,

我想限制WordPress中帖子标题的字符


假设我发表了一篇150个字符的文章,但我只想显示120个字符。有什么办法吗?

您可以在
wp content/themes/your theme/header.php
中编辑主题的标题。然后根据字符数更改标题:

<title><?php
    $title = wp_title(' - ', false, 'right');
    if (strlen($title) > 120) $title = substr($title, 0, 117) . "...";
    echo $title;
?></title>


在这方面,这是最好的,我使用了这个。本网站介绍了5种降低成本的方法:


请将您的答案格式化为链接和常规文本,并提供链接页面的摘要。
<a href="<?php echo $blogUrl; ?>?p=<?php echo the_ID(); ?>">
<?php 
    if (strlen($post->post_title) > 120) {
        echo substr(the_title($before = '', $after = '', FALSE), 0, 120) . '...'; 
    } else {
        the_title();
    } 
?>
</a>