Last active
August 29, 2015 14:02
-
-
Save aisin/0bf7f622462fff521ac5 to your computer and use it in GitHub Desktop.
WordPress 修改摘要的默认字数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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