有没有办法限制帖子标题的字数?
我已经在网上找过了,但什么也没找到。
我所知道的是,只有帖子的内容可以被限制或摘录。
发布于 2012-12-11 18:07:05
只要你想用有限的词来显示你的标题,就可以简单地使用它
<?php echo wp_trim_words( get_the_title(), 5 ); ?>
将上面代码中的数字5替换为您需要显示的任意数量的单词。
致以问候。
发布于 2012-12-12 02:34:27
以下内容将限制用户在管理区域中输入的字符数,例如,在撰写帖子时。
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并将这些函数应用到上面的代码中。
https://stackoverflow.com/questions/13816272
复制相似问题