Skip to content

Instantly share code, notes, and snippets.

@aisin
Last active August 29, 2015 14:02
Show Gist options
  • Save aisin/0bf7f622462fff521ac5 to your computer and use it in GitHub Desktop.
Save aisin/0bf7f622462fff521ac5 to your computer and use it in GitHub Desktop.
WordPress 修改摘要的默认字数
<?php
/**********************************************
**
**在主题文件夹下的functions.php中加入以下代码:
**
***********************************************/
//修改字数
function custom_excerpt_length( $length ) {
return 200; //填写需要截取的字符数,1个汉字=2个字符
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
//如果需要修改结尾的显示方式,将省略号修改成该文章的链接,用以下方法:
function new_excerpt_more($more) {
global $post;
return ' <a href="'. get_permalink($post->ID) . '">Read More</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment