10

i have try many methods after searching on internet but unable to ramove Nothing Found from my 404 page title how to do it please help me

even i have us this in my 404 page header if( is_404() ) echo '404 message goes here | '; else wp_title( '|', true, 'right' );

i also ramove php title function and five their my own header but still not changing why ?

3 Answers 3

17

I would use the wp_title filter hook:

function theme_slug_filter_wp_title( $title ) {
    if ( is_404() ) {
        $title = 'ADD 404 TITLE TEXT HERE';
    }
    // You can do other filtering here, or
    // just return $title
    return $title;
}
// Hook into wp_title filter hook
add_filter( 'wp_title', 'theme_slug_filter_wp_title' );

This will play nicely with other Plugins (e.g. SEO Plugins), and will be relatively forward-compatible (changes to document title are coming soon).

EDIT

If you need to override an SEO Plugin filter, you probably just need to add a lower priority to your add_filter() call; e.g. as follows:

add_filter( 'wp_title', 'theme_slug_filter_wp_title', 11 );

The default is 10. Lower numbers execute earlier (e.g. higher priority), and higher numbers execute later (e.g. lower priority). So, assuming your SEO Plugin uses the default priority (i.e. 10), simply use a number that is 11 or higher.

3
  • Thanks that was not changing because of my seo plugin but thanks for response :) But Now i Have one more problem my 404 page gives 404 header response how can i change that ?
    – realcoder
    Commented Oct 12, 2011 at 13:57
  • The SEO Plugin is almost certainly using the wp_title filter. If you need to override it, add a priority to your add_filter() call. See answer update. Commented Oct 12, 2011 at 15:56
  • Adding a higher priority did the trick for me.
    – Alex
    Commented Apr 21, 2017 at 14:44
3

WordPress 4.4 and up

The accepted answer no longer works as wp_title is deprecated in WordPress 4.4 and up (see here). We must now use the document_title_parts filter hook instead.

Here is the accepted answer rewritten to use document_title_parts.

function theme_slug_filter_wp_title( $title_parts ) {
    if ( is_404() ) {
        $title_parts['title'] = 'ADD 404 TITLE TEXT HERE';
    }

    return $title_parts;
} 

// Hook into document_title_parts
add_filter( 'document_title_parts', 'theme_slug_filter_wp_title' );
1
  • Thank you, do you know if they changed anything in WP 6.4? Can't get it to work. This code goes into functions.php, right? Commented Nov 30, 2023 at 10:42
0

The following code works fine with the twenty eleven theme:

if ( is_404() ) { 
  echo __('Nothing Found','mytheme')
}

So the title code looks like the following:

<title>
<?php 

global $page, $paged;

if ( is_404() ) { 
  echo __('Nothing Found | ','mytheme');
}
else {
  wp_title( '|', true, 'right' );
} 

?>
</title>
3
  • 3
    I strongly recommend always outputting <title> text using the wp_title() function, either by passing an argument, or using the wp_title filter hook, so that the code plays nicely with other Plugins that attempt to modify <title> text. Commented Oct 12, 2011 at 13:20
  • Thanks that was not changing because of my seo plugin but thanks for response :)
    – realcoder
    Commented Oct 12, 2011 at 13:56
  • But Now i Have one more problem my 404 page gives 404 header response how can i change that ?
    – realcoder
    Commented Oct 12, 2011 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.