WPML
SignaturePHP
add_filter( 'wpml_is_redirected', 'callable $function_to_add, 10, 3 );

Description

WPML automatically tries to redirect visitors to the canonical URL when it does find a match. This hook allows to disable this WPML functionality.

Arguments

There are three parameters being passed to this filter:

  • $redirectbool

    Boolean value to define whether or not to disable WPML canonical URL redirection actions.
  • $post_idinteger

    post ID
  • $queryarray

    The WordPress query array.

Example Usage

The following example prevents WPML canonical URL redirection for a Custom Post Type with a slug of “city”

PHP
function mytheme_do_not_redirect_city_post_type( $redirect, $post_id, $query ) {
    if ( 'city' === $query->get( 'post_type' ) ) {
       return false;
     }
    return $redirect;
    };
add_filter( 'wpml_is_redirected', mytheme_do_not_redirect_city_post_type, 10, 3 );