![]()
1 修复Cravatar头像无法显示问题
/*修复wordpress上Cravatar头像无法显示问题*/
if ( ! function_exists( 'get_cravatar_url' ) ) {
/**
*替换Gravatar头像为Cravatar头像
*
* @param string $url
*
* @return string
*/
function get_cravatar_url( $url ) {
$sources = array(
'www.gravatar.com',
'0.gravatar.com',
'1.gravatar.com',
'2.gravatar.com',
'secure.gravatar.com',
'cn.gravatar.com'
);
return str_replace( $sources, 'cravatar.cn', $url );
}
add_filter( 'um_user_avatar_url_filter', 'get_cravatar_url', 1 );
add_filter( 'bp_gravatar_url', 'get_cravatar_url', 1 );
add_filter( 'get_avatar_url', 'get_cravatar_url', 1 );
}
- 进入WP网站站点后台
- 点击“外观”->“主题文件编辑器”选项卡
- 点击右侧主题文件下的模板函数选项卡
- 复制以上函数,插入到模板函数 (functions.php)的最后一行
- 最后不要忘记点击更新文件,然后刷新页面,Cravatar头像即可正常显示
2 自定义文章摘要长度
对于一个博客网站,我们通常需要在站点主页展示博客文章摘要。但是在WordPress写文章时,其人工摘要栏并不是必填的,而是可选的。
如果人工摘要栏为空,那么WordPress会自动创建一个文章摘要通过使用该篇文章的前55个字符;如果人工摘要不为空,那么博主使用的Blogier主题默认会以人工摘要的前15个字符作为文章摘要。但是15个字长的文章摘要其实是非常短的,有时很难展现出文章的内容,不过幸运的是,我们可以通过主题文件编辑器自定义文章摘要长度,具体步骤如下:
- 进入WP网站站点后台
- 点击“外观”->“主题文件编辑器”选项卡
- 点击右侧主题文件下的模板函数选项卡
- Ctrl+F搜索excerpt
- 找到与excerpt摘要长度有关的变量,并修改其值即可
Blogier主题excerpt摘要长度修改如下(此处自定义文章摘要长度为55个字符):
if ( ! function_exists( 'blogier_blog_content' ) ) :
function blogier_blog_content() {
$blogus_blog_content = get_theme_mod('blogus_blog_content','excerpt');
if ( 'excerpt' == $blogus_blog_content ){
$blogus_excerpt = blogus_the_excerpt( absint( 55 ) );
if ( !empty( $blogus_excerpt ) ) :
echo wp_kses_post( wpautop( $blogus_excerpt ) );
endif;
} else{
the_content( __('Read More','blogier') );
}
}
endif;