check url parameter if not redirect wordpress

You can check the URL parameter and redirect in WordPress by adding the following code to your theme's functions.php file:

function check_url_parameter() {
    if ( isset( $_GET['your_parameter'] ) ) {
        // Perform your desired action when the parameter is present
    } else {
        wp_redirect( home_url() ); // Redirect to the home page if the parameter is not present
        exit;
    }
}
add_action( 'template_redirect', 'check_url_parameter' );

This code creates a function called check_url_parameter that hooks into the template_redirect action in WordPress. It checks for the presence of a specific URL parameter using isset( $_GET['your_parameter'] ). If the parameter is present, you can perform your desired action within the conditional statement. If the parameter is not present, it calls wp_redirect( home_url() ) to redirect the user to the home page and then exits the script using exit;.