在 WordPress 中修改默认的文章文字长度可以通过添加以下代码到主题的 functions.php 文件中:
function custom_excerpt_length( $length ) {
return 50; // 修改数字即可,此处为50个字
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
以上代码会将默认的文章摘要长度限制为50个字。如果想要修改文章正文的长度,可以添加以下代码:
function custom_excerpt_length( $length ) {
return 200; // 修改数字即可,此处为200个字
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
function custom_content_length( $content ) {
return substr( $content, 0, 500 ); // 修改数字即可,此处为500个字
}
add_filter( 'the_content', 'custom_content_length', 999 );
以上代码会将文章正文的长度限制为500个字。需要注意的是,添加代码之后需要保存文件并更新主题才能生效。