I'm tryying to prevent search engines from indexing my 404 page which is in a template called 404.php. I do not create an actual page, I simply rely on the php template for my 404 errors.

I'm using the code below and it's not working, I'm unsure what the best way to go about this is and I would appreciate help.

<?php if(is_single('404.php')): ?>
<?php endif; ?>

This won't ever return true:

if ( is_single( '404.php' ) ) {}

The is_single() conditional only returns true in a single blog post context. The parameter it accepts is a post ID, slug, or title.

The 404.php file is a template file, not a post. Use is_404() instead:

if ( is_404() ) {}

Isn't this fixed by creating a robot.txt at the root of your ftp like so:

User-agent: *
Disallow: /404.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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