2012-12-11 48 views
2

有没有办法限制帖子标题的字数?限制帖子标题中的字数

我通过互联网搜索,但没有发现。

我只知道,只有帖子的内容可以是限制或摘录。

+0

简单的解决方案:https://wordpress.stackexchange.com/a/291096/133699 – Super

回答

4

根本用不完这在要以有限的话

<?php echo wp_trim_words(get_the_title(), 5); ?> 

,以显示你的标题和你需要显示任何的字数替换上面的代码号5。

问候。

1

下面将限制写帖子的时候,用户可以在管理区,即输入的字符数。

add_action('admin_head-post.php', 'so_13816272_limit_input_title'); 

function so_13816272_limit_input_title() 
{ 
    global $current_screen; 
    // Not our post type, exit earlier 
    if('post' != $current_screen->post_type) 
     return; 
    ?> 
    <script type="text/javascript"> 
     jQuery(document).ready(function($) 
     { 
      $('#title').keyup(function() 
      { 
       var $this = $(this); 
       if($this.val().length > 50) 
        $this.val($this.val().substr(0, 50));   
      });   
     });  
    </script> 
    <?php 
} 

如果你想要做一个数,是指this article和适应功能分成上面的代码。