Based on the limited detail of your question something as per the following is a rough gist of what you could do.
In your theme functions.php file:
<?php
function handle_request () {
if (isset($_GET['custom_id']) && isset($_GET['custom_id_nonce']) ) {
if ( wp_verify_nonce($_GET['custom_id_nonce'], 'custom_id_action') ) {
$id = $_GET['custom_id'];
// FIRST
// do something with $id
// THEN
// possibly redirect somewhere else or back to referrer
// e.g. wp_safe_redirect( wp_get_referer() );
// see https://codex.wordpress.org/Function_Reference/wp_get_referer
// see https://codex.wordpress.org/Function_Reference/wp_safe_redirect
} else {
// handle failure state, nonce value is incorrect...
}
}
// if here, the request was likely not for you
}
add_action( 'init', 'handle_request' );
In your theme template file:
<a href="https://wordpress.stackexchange.com/questions/346258/<?php echo wp_nonce_url( home_url("?custom-id=123'), 'custom_id_action', 'custom_id_nonce' );?>">CLICK ME</a>
In the above example, where home_url('?custom-id=123')
is stated, you may want to change the basis for this URL to be the current URL the user is on.
Important reading: