WordPress

推荐列表 站点导航

当前位置:首页 > 建站教程 > WordPress >

限制WordPress文章标题字数方法

来源:网络整理  作者:  发布时间:2020-12-16 04:56
WordPress文章标题太长会导致主题异常并影响美观,很多朋友咨询该如何限制WordPress文章标题长度字数,今天就为大家...

echo '<script>jQuery(document).ready(function(){

if($this.val().length > 46)

});</script>';

}

return wp_trim_words( $title, 10, '' );

$this.val($this.val().substr(0, 46));

// limit to ten words

$title = htmlspecialchars($mytitleorig, ENT_QUOTES, "UTF-8");

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

jQuery("#title").keyup( function() {

}

function limit_word_count($title) {

if(strlen($title) >= ($limit+3)) {

$len = 5; //change this to the number of words

备注:如何出现转移乱码等可以采用这个the_title_attribute()替换get_the_title()

}

后端限制WordPress文章标题

wp_trim_words(get_the_titlee(),5);

//限制文章标题输入字数

$post_type = get_post_type( $post_id );

function title_count_js(){

$mytitleorig = get_the_title();

$title = mb_substr($title, 0, $limit) . $pad; }

{

add_filter( 'the_title', 'wpse_75691_trim_words' );

jQuery("#title_counter").val(jQuery("#title").val().length);

add_filter('the_title', 'limit_word_count');

前端限制文章标题字数

function wpse_75691_trim_words( $title )

return $title;

}

function wpse_75691_trim_words_by_post_type( $title, $post_id )

调用:short_title(),或者使用以下更简单方法

echo wp_trim_words( get_the_title(), 10, '...' );

jQuery("#titlewrap #title").keyup( function() {

WordPress文章标题太长会导致主题异常并影响美观,很多朋友咨询该如何限制WordPress文章标题长度字数,今天就为大家分享一下限制WordPress文章标题字数方法,包括前端限制及后端编辑器限制。

// limit to ten words

}

add_action( 'admin_head-post-new.php', 'title_count_js');

{

if (str_word_count($title) > $len) {

限制WordPress文章标题字数方法 (https://www.wpmee.com/) WordPress开发教程 第1张

function short_title() {

$pad="";

var $this = jQuery(this);

jQuery("#title_counter").val(jQuery("#title").val().length);

$limit = "15"; //显示的字数,可根据需要调整

return $title;

});

});

if ( 'product' !== $post_type )

//其它

现在大部分的 PHP 服务器都支持了 MB 库(mbstring 库 全称是 Multi-Byte String 即各种语言都有自己的编码,他们的字节数是不一样的,目前php内部的编码只支持ISO-8859-*, EUC-JP, UTF-8 其他的编码的语言是没办法在 php 程序上正确显示的。解决的方法就是通过 php 的 mbstring 函数库来解决),所以我们可以放心的使用这个用于控制字符串长度的函数。

echo $title;

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>");

echo mb_strimwidth(htmlspecialchars_decode(get_the_title()), 0, 50, '...');

$title = substr($title, 0, $keys[$len]);

$keys = array_keys(str_word_count($title, 2));

WordPress 自带的函数是直接输出文章标题长度的,标题太长了就会自动换行,解决办法是使用mbstring函数库来解决,这样就可以指定具体标题字数。

return wp_trim_words( $title, 10, '' );

add_filter( 'the_title', 'wpse_75691_trim_words_by_post_type', 10, 2 );

}

相关热词: 方法

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jz/wp/4332.shtml

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

限制WordPress文章标题字数方法

2020-12-16 编辑:

echo '<script>jQuery(document).ready(function(){

if($this.val().length > 46)

});</script>';

}

return wp_trim_words( $title, 10, '' );

$this.val($this.val().substr(0, 46));

// limit to ten words

$title = htmlspecialchars($mytitleorig, ENT_QUOTES, "UTF-8");

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

jQuery("#title").keyup( function() {

}

function limit_word_count($title) {

if(strlen($title) >= ($limit+3)) {

$len = 5; //change this to the number of words

备注:如何出现转移乱码等可以采用这个the_title_attribute()替换get_the_title()

}

后端限制WordPress文章标题

wp_trim_words(get_the_titlee(),5);

//限制文章标题输入字数

$post_type = get_post_type( $post_id );

function title_count_js(){

$mytitleorig = get_the_title();

$title = mb_substr($title, 0, $limit) . $pad; }

{

add_filter( 'the_title', 'wpse_75691_trim_words' );

jQuery("#title_counter").val(jQuery("#title").val().length);

add_filter('the_title', 'limit_word_count');

前端限制文章标题字数

function wpse_75691_trim_words( $title )

return $title;

}

function wpse_75691_trim_words_by_post_type( $title, $post_id )

调用:short_title(),或者使用以下更简单方法

echo wp_trim_words( get_the_title(), 10, '...' );

jQuery("#titlewrap #title").keyup( function() {

WordPress文章标题太长会导致主题异常并影响美观,很多朋友咨询该如何限制WordPress文章标题长度字数,今天就为大家分享一下限制WordPress文章标题字数方法,包括前端限制及后端编辑器限制。

// limit to ten words

}

add_action( 'admin_head-post-new.php', 'title_count_js');

{

if (str_word_count($title) > $len) {

限制WordPress文章标题字数方法 (https://www.wpmee.com/) WordPress开发教程 第1张

function short_title() {

$pad="";

var $this = jQuery(this);

jQuery("#title_counter").val(jQuery("#title").val().length);

$limit = "15"; //显示的字数,可根据需要调整

return $title;

});

});

if ( 'product' !== $post_type )

//其它

现在大部分的 PHP 服务器都支持了 MB 库(mbstring 库 全称是 Multi-Byte String 即各种语言都有自己的编码,他们的字节数是不一样的,目前php内部的编码只支持ISO-8859-*, EUC-JP, UTF-8 其他的编码的语言是没办法在 php 程序上正确显示的。解决的方法就是通过 php 的 mbstring 函数库来解决),所以我们可以放心的使用这个用于控制字符串长度的函数。

echo $title;

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>");

echo mb_strimwidth(htmlspecialchars_decode(get_the_title()), 0, 50, '...');

$title = substr($title, 0, $keys[$len]);

$keys = array_keys(str_word_count($title, 2));

WordPress 自带的函数是直接输出文章标题长度的,标题太长了就会自动换行,解决办法是使用mbstring函数库来解决,这样就可以指定具体标题字数。

return wp_trim_words( $title, 10, '' );

add_filter( 'the_title', 'wpse_75691_trim_words_by_post_type', 10, 2 );

}

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jz/wp/4332.shtml

相关文章

风云图片

推荐阅读

返回WordPress频道首页