2012-12-11 86 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和適應功能分成上面的代碼。