限制WordPress文章标题输入字数

昨天群里有朋友询问如何限制WordPress文章标题输入字数,下面倡萌分享两种方法。

limit-length-of-wordpress-title-input-wpdaxue_com

方法1:直接在的当前主题的 functions.php 文件添加下面的代码即可:

//限制文章标题输入字数 From wpdaxue.com
function title_count_js(){
	echo '<script>jQuery(document).ready(function(){
	jQuery("#titlewrap").after("<div><small>标题字数: </small><input type=\"text\" value=\"0\" maxlength=\"3\" size=\"3\" id=\"title_counter\" readonly=\"\" style=\"background:#fff;\"> <small>最大长度不得超过 46 个字</small></div>");
	jQuery("#title_counter").val(jQuery("#title").val().length);
	jQuery("#title").keyup( function() {
	jQuery("#title_counter").val(jQuery("#title").val().length);
	});
	jQuery("#titlewrap #title").keyup( function() {
	var $this = jQuery(this);
	if($this.val().length > 46)
	$this.val($this.val().substr(0, 46));
	});
});</script>';
}
add_action( 'admin_head-post.php', 'title_count_js');
add_action( 'admin_head-post-new.php', 'title_count_js');

上面的代码支持实时统计标题字数,并且超过字数后将会被截止,效果如本文配图所示。默认最大允许输入 46 个字,请根据自己的需求,修改代码中 3 处出现 46 的地方。

参考资料:http://www.rvwd.net/news/limit-length-of-an-input-and-display-count-php-jquer

方法2:下载安装 Limit a post title to X characters 插件,支持设置字数和是否限制管理员等,实时统计字数,超过字数限制就没办法提交文章。

来源:

https://www.wpdaxue.com/limit-length-of-wordpress-title-input.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32454.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?