Logout user if click on a custom page link

yes we make custom page as logout link on this way add this in function.php

add_action( 'init', 'log_out_user' );function log_out_user() {
global $wp;
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; //get current page url
if(!empty(get_current_user_id()) && $url == 'example.com/logout' ) //check if user is logged in and current page url
{
    wp_logout(); //this will logout user
    $siteUrl = site_url(); //get site url 
    wp_redirect($siteUrl);//add this if you want to redirect to site url after logout
}}