remove filter url in wordpress

PHOTO EMBED

Thu Feb 27 2025 07:20:18 GMT+0000 (Coordinated Universal Time)

Saved by @hamzahanif192

 function remove_query_parameters() {
    if (is_product() || is_archive()) {
        $url = $_SERVER['REQUEST_URI'];
        $clean_url = strtok($url, '?'); // Remove everything after "?" (including query parameters)
        
        // Check if the URL has query parameters and perform a redirect
        if ($url != $clean_url) {
            wp_redirect($clean_url, 301); // Permanent redirect (301)
            exit;
        }
    }
}
add_action('template_redirect', 'remove_query_parameters');
content_copyCOPY