Rename sitewide page headers so "Blog" doesn't appear
-
I’m trying to share some pages on Facebook but I noticed the default page title is:
Sitename | Blog | Article name
Is there a way to omit blog from it so it just appears as “Sitename | Article name” ?
I’m not sure how this can be done. Thank you.
-
Here’s a plugin that sounds like what you’re wanting.
I removed the /blog from the Side Admin>Blogs>Edit>Permalink Structure manually.
I installed the plugin but it doesn’t seem to redact the “Blog |” part of the page title for some reason…
Th plugin mentioned above is for wpmu in subdirectory install.
for your proble, here is a little hacked code of bp_page_title , It will rewrite the title of single article only.
put this code in bp-custom.php
add_filter("bp_page_title", "bpdev_blog_title",10,2);
function bpdev_blog_title($complete_title,$title_old)
{//hack page title for single article
global $bp,$current_blog;
if ( bp_is_blog_page() ){
if ( is_single() ){
$title = __( $post->post_title, 'buddypress' );
if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
$blog_title = get_blog_option( $current_blog->blog_id, 'blogname' );
} else {
$blog_title = get_blog_option( BP_ROOT_BLOG, 'blogname' );
}
return $blog_title . ' | ' . esc_attr( $title );
}
}
return $complete_title;
}Edit: there was a small mistake, Edited to correct it
This seems to be close to the fix. All that appears is “Sitename |” which is good because it omits the word blog, but the article name is missing too for some reason. You’re on the right track.
doh! I missed while modifying the bp_page_title
But the global line as
global $bp,$current_blog,$post;
So the modified code for function looks like
function bpdev_blog_title($complete_title,$title_old)
{//hack page title for single article
global $bp,$current_blog,$post;
if ( bp_is_blog_page() ){
if ( is_single() ){
$title = __( $post->post_title, 'buddypress' );
if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
$blog_title = get_blog_option( $current_blog->blog_id, 'blogname' );
} else {
$blog_title = get_blog_option( BP_ROOT_BLOG, 'blogname' );
}
return $blog_title . ' | ' . esc_attr( $title );
}
}
return $complete_title;
}Hmm… I updated the code but it seems to go back to the original “Sitename | Blog | Article name” format for some reason.
That is because you missed this line
add_filter("bp_page_title", "bpdev_blog_title",10,2);
This should also be present in the bp-custom.php other wise no filtering of title will be done.
function bpdev_blog_title($complete_title,$title_old)
{//hack page title for single article
global $bp,$current_blog,$post;
if ( bp_is_blog_page() ){
if ( is_single() ){
$title = __( $post->post_title, 'buddypress' );
if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
$blog_title = get_blog_option( $current_blog->blog_id, 'blogname' );
} else {
$blog_title = get_blog_option( BP_ROOT_BLOG, 'blogname' );
}
return $blog_title . ' | ' . esc_attr( $title );
add_filter("bp_page_title", "bpdev_blog_title",10,2);
}
}
return $complete_title;
}
It reverts back to the old format for some reason.
ahh alright, you are either missing the one or the other. hmm.. I think, I should have pasted both the piece of code together.
Well, here it goes, and I hope, this must work
add_filter("bp_page_title", "bpdev_blog_title",10,2);
function bpdev_blog_title($complete_title,$title_old)
{//hack page title for single article
global $bp,$current_blog,$post;
if ( bp_is_blog_page() ){
if ( is_single() ){
$title = __( $post->post_title, 'buddypress' );
if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
$blog_title = get_blog_option( $current_blog->blog_id, 'blogname' );
} else {
$blog_title = get_blog_option( BP_ROOT_BLOG, 'blogname' );
}
return $blog_title . ' | ' . esc_attr( $title );
}
}
return $complete_title;
}Please use the complete code and put it into your bp-custom.php. let me know If it still does not work.
Wow, works like a charm! Thank you very much. This is extremely helpful.
Would it be easier to change “Blog” to something else? The above function works but only on single post pages. You still see “Blog” showing up in the titles on archives (tag pages, category pages, etc.). I need to either change it or remove it site-wide… not just on single post pages.
hi David
As I mentioned above, it is nothing but a hack of the bp_get_page_title, here is adaption you can use
add_filter("bp_page_title", "bpdev_blog_title",10,2);
function bpdev_blog_title($complete_title,$title_old){
global $bp,$current_blog,$wp_query,$post;
if ( bp_is_blog_page() ) {//if this is blog page
if ( is_single() ) {
$title = __($post->post_title, 'buddypress' );
} else if ( is_category() ) {
$title = __( 'Categories | ' . ucwords( $wp_query->query_vars['category_name'] ), 'buddypress' );
} else if ( is_tag() ) {
$title = __( 'Tags | ' . ucwords( $wp_query->query_vars['tag'] ), 'buddypress' );
} else if ( is_page() ){
$title = $post->post_title;
}
if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
$blog_title = get_blog_option( $current_blog->blog_id, 'blogname' );
} else {
$blog_title = get_blog_option( BP_ROOT_BLOG, 'blogname' );
}
if(!empty($title))
return $blog_title . ' | ' . esc_attr( $title );
}
//so on blog home page, It will show Blog,reason we have excluded that page
return $complete_title;
}Hope, It should help you, you can modify the various titles as you wish for the category/tags etc.
Awesome. Thanks! One small tweak. This code just outputs the slug with an initial capital letter:
ucwords( $wp_query->query_vars['category_name'] ), 'buddypress' )
ucwords( $wp_query->query_vars['tag'], 'buddypress' )Would be nice to use a nice name instead (I’ll have to look in the DB or print out the variables to see if there’s some other variable I could use)… or use some PHP string command (if possible) to strip the dashes and capitalize all words.
I tweaked this for my needs. It now takes the ugly slugs and replaces hyphens with spaces and capitalizes the words. It also throws in a few titles for custom pages and my custom taxonomy.
function bpdev_blog_title($complete_title,$title_old){
global $bp,$current_blog,$wp_query,$post;
if ( bp_is_blog_page() ) {//if this is blog page
if ( is_single() ) {
$title = __($post->post_title, 'buddypress' );
} else if ( is_category() ) {
$cat = ucwords( str_replace("-", " ", $wp_query->query_vars['category_name'] ) );
$title = __( 'Topics | ' . $cat, 'buddypress' );
} else if ( is_tag() ) {
$tag = ucwords( str_replace("-", " ", $wp_query->query_vars['tag'] ) );
$title = __( 'Tags | ' . $tag, 'buddypress' );
} else if ( is_tax() ) {
$tax = ucwords( str_replace("-", " ", $wp_query->query_vars['term'] ) );
$title = __( 'Issues | ' . $tax, 'buddypress' );
} else if ( is_home() ) {
$title = __( 'Archives' );
} else if ( is_page( 'issues' ) ) {
$title = __( 'Issues' );
} else if ( is_page( 'topics' ) ) {
$title = __( 'Topics' );
}
if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
$blog_title = get_blog_option( $current_blog->blog_id, 'blogname' );
} else {
$blog_title = get_blog_option( BP_ROOT_BLOG, 'blogname' );
}
if(!empty($title)) return $blog_title . ' | ' . esc_attr( $title );
}
//so on blog home page, It will show Blog, reason we have excluded that page
return $complete_title;
}
- The topic ‘Rename sitewide page headers so "Blog" doesn't appear’ is closed to new replies.