简体   繁体   中英

Wordpress - Remove "Home" from home page title

Guys I'm having an issue with the home page title of my wordpress blog after i updated the wordpress to 4.4. I'm not sure if its because of the update. The issue is, I'm getting "Home" prefix for the home page title. Here's my website - www.autodevot.com

In the wordpress Settings > General, in the Site Title section, I've written Autodevot . And in the Tagline section, I've written Automotive World News | Car News and Reviews | Upcoming Cars in India . So earlier, this tagline section was appearing in the home page title. Now for some reason, Its adding "Home" prefix for the home page title. So now the title comes as Home - Autodevot. I need to get rid of that "Home" and want the tagline section to appear in the title like before. Title for rest of the pages are appearing fine. Problem is only with the home page title. I opened the header.php and the code is like this

<?php
if ( ! function_exists( '_wp_render_title_tag' ) ) {
function theme_slug_render_title() {
?>
<title><?php wp_title( '|', true, 'right' ); ?></title>
<?php
}
add_action( 'wp_head', 'theme_slug_render_title' );
}
?>

Any help?

Many sources on this topic points to eithe using a plugin or changing some PHP code. However, a newer feature (WordPress 4.7) allows adding custom CSS to a theme (which is bound to that theme, but is not overwritten at theme updates). This saves the need to create a child theme. This tool is accessed through the "Additional CSS" tab in theme customization.

Taking inspiration from this blog post about how to select the page title in CSS, I've added:

.home .entry-title {display: none;}

to hide the h1 title "Home" on my home page. I suspect that the home class is generic for all front pages (no matter the actual title of the home page).

As an alternative, to remove the title on all pages (but not blog posts):

.page .entry-title {display: none;}

Finally, as explained in the blog post, it is possible to target a specific page with its id:

.page-id-177 .entry-title {display: none;}

where page-id-177 comes from the class attribute of the <body> tag of the page of interest.

Thanks to the live preview, it's easy to see if the CSS is effective!

replace your code with this code

<?php
if ( ! function_exists( '_wp_render_title_tag' ) && !is_home() || !is_front_page() ) {
function theme_slug_render_title() {
?>

<title><?php wp_title( '|', true, 'right' ); ?></title>
<?php
}
add_action( 'wp_head', 'theme_slug_render_title' );
}
?>

You can try this one, Just add your theme functions.php

add_filter('wp_title', 'filter_pagetitle');
function filter_pagetitle($title) {
    global $wp_query;
    if (is_front_page()){
        return $wp_query->post->post_title;
    }
}

just change the file name as one of your keyword. For wordpress, change the page title to your keywords.

I did it and works fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM