BuddyPress title 修改

BuddyPress 1.0 home 页默认的title 是”博客标题 — Home”,比如SinoBlog.net 首页的浏览器标题就是”SinoBlog.net — Home”。

Home 对网站/博客而言,其实没有任何意义,网页的title 对于搜索引擎的收录非常重要,所以需要将其修改。

BuddyPress title 的修改方法是,打开”/bp-core/bp-core-templatetags.php”,大概是从第468 行开始定义title 的。

我就只修改了SinoBlog.net 首页的title,如下:

  1. function bp_page_title() {
  2. global $bp, $post, $wp_query;
  3.  
  4. if ( is_home() && bp_is_page( 'home' ) ) {
  5. $title = __( '免费提供专业WordPress 博客服务', 'buddypress' );
  6. } else if ( bp_is_blog_page() ) {
  7. if ( is_single() ) {
  8. $title = __( 'Blog — ' . $post->post_title, 'buddypress' );
  9. } else if ( is_category() ) {
  10. $title = __( 'Blog — Categories — ' . ucwords( $wp_query->query_vars['category_name'] ), 'buddypress' );
  11. } else if ( is_tag() ) {
  12. $title = __( 'Blog — Tags — ' . ucwords( $wp_query->query_vars['tag'] ), 'buddypress' );
  13. } else {
  14. $title = __( 'Blog', 'buddypress' );
  15. }
  16. } else if ( !empty( $bp->displayed_user->fullname ) ) {
  17. $title = strip_tags( $bp->displayed_user->fullname . ' — ' . ucwords( $bp->current_component ) . ' — ' . $bp->bp_options_nav[$bp->current_component][$bp->current_action]['name'] );
  18. } else if ( $bp->is_single_item ) {
  19. $title = ucwords( $bp->current_component ) . ' — ' . $bp->bp_options_title;
  20. } else if ( $bp->is_directory ) {
  21. if ( !$bp->current_component )
  22. $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( BP_MEMBERS_SLUG ) );
  23. else
  24. $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( $bp->current_component ) );
  25. } else {
  26. global $post;
  27. $title = get_the_title($post->ID);
  28. }
  29. echo apply_filters( 'bp_page_title', get_blog_option( BP_ROOT_BLOG, 'blogname' ) . ' — ' . $title, $title );
  30. }

记录一下,因为title 以后可能还需要修改 :-)

Comments are closed.