# Send Secondary-Language 404s to That Language's Homepage

> When a visitor hits a missing page in a non-default WPML language, sends them to the homepage of that language instead of a 404, keeping them in their language.

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

## Code

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

    $current = apply_filters( 'wpml_current_language', null );
    $default = apply_filters( 'wpml_default_language', null );

    if ( ! $current || $current === $default || 'all' === $current ) {
        return;
    }

    wp_safe_redirect( apply_filters( 'wpml_home_url', home_url( '/' ) ), 302 );
    exit;
} );
```

## Notes

Uses a 302 redirect so search engines keep reporting real broken links; change to 301 if you prefer. The default language keeps its normal 404 page.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Send Secondary-Language 404s to That Language's 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/
