Using WordPress ‘is_redirect()’ PHP function

The is_redirect() WordPress PHP function checks if the current page is a redirection page.

Usage

is_redirect();

Parameters

  • No parameters

More information

See WordPress Developer Resources: is_redirect()

Examples

Check if the current page is a redirection page

if (is_redirect()) {
    echo "This is a redirection page.";
} else {
    echo "This is not a redirection page.";
}

Add a message to redirection pages

function add_message_to_redirect() {
    if (is_redirect()) {
        echo "You are being redirected. Please wait.";
    }
}
add_action('wp_footer', 'add_message_to_redirect');

Change the title of redirection pages

function change_redirect_page_title($title) {
    if (is_redirect()) {
        return "Redirecting...";
    }
    return $title;
}
add_filter('the_title', 'change_redirect_page_title');

Apply custom CSS to redirection pages

function add_redirect_css() {
    if (is_redirect()) {
        echo '<style>body { background-color: #f1f1f1; }</style>';
    }
}
add_action('wp_head', 'add_redirect_css');

Track redirection pages using Google Analytics

function track_redirect_pages() {
    if (is_redirect()) {
        echo "<script>
        gtag('event', 'redirect', {'event_category': 'Redirection'});
        </script>";
    }
}
add_action('wp_footer', 'track_redirect_pages');