# Send Polylang 404s to the Visitor's Language Homepage

> Redirects visitors who hit a missing page in a secondary Polylang language to that language's homepage, so they are not dropped onto a 404 page.

- Type: PHP
- Runs: Frontend cl
- Category: [Multilingual](https://wpide.com/library/category/multilingual/)
- Tags: polylang, 404, redirect
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/pll-404-to-language-home/

## Code

```php
add_action( 'template_redirect', function () {
    if ( ! is_404() || ! function_exists( 'pll_current_language' ) ) {
        return;
    }

    $current = pll_current_language();

    if ( ! $current || pll_default_language() === $current ) {
        return;
    }

    wp_safe_redirect( pll_home_url( $current ), 302 );
    exit;
} );
```

## Notes

Uses a 302 so your 404 reports still show broken links. The default language keeps the normal 404 page.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Send Polylang 404s to the Visitor's Language Homepage" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
