WordPress.org

Support

Support » Themes and Templates » Noindex 404 pages from functions.php in child theme

Noindex 404 pages from functions.php in child theme

  • I’m setting up a custom 404 page for my website that will be more helpful to visitors who have gotten a bad link. While I’m doing that, I would like to make sure that the 404 page’s meta robots tag is set to noindex, follow. (I know that search engine robots will usually not index 404 pages, but I’d like to be certain.)

    All the suggestions I’m finding for doing that involve adding an if statement to the theme’s header.php file, which is definitely not ideal. (I’m using a child theme and while I could duplicate and modify the parent theme’s header.php, I would rather not do that — there’s a lot of other stuff in that file and I want to make sure it updates when the theme updates!)

    Is there a function I can add to the child’s functions.php to change the meta robots tags only for 404s? I’m guessing it would involve modifying the wp_head() function, but I’m afraid I have no idea how.

    Thanks!

  • The topic ‘Noindex 404 pages from functions.php in child theme’ is closed to new replies.
Skip to toolbar