{{site_url}} on functions.php

I have some customisation on my Child-Theme’s functions.php that calls the Site URL. I’ve received the snippet on wich I have to write the website URL. I believe it would be possible to add some code like {{site_url}} that uses the actual site URL.

add_action('check_admin_referer', 'logout_without_confirm', 10, 2);
function logout_without_confirm($action, $result)
{
    /**
     * Allow logout without confirmation
     */
    if ($action == "log-out" && !isset($_GET['_wpnonce'])) {
        $redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : 'https://mydomain.com/?loggedout=true';
        $location = str_replace('&', '&', wp_logout_url($redirect_to));
        header("Location: $location");
        die;
    }
}

This would allow me to use this snipet on multiple sites, without having to change the Site URL every time. The idea would be tu have nstead of “https://mydomain.com/?loggedout=true” for something like “{{site_URL}}/?loggedout=true” instead.

Would that be possible? Or some other PHP code? Thank you very much in advance!

Hi Fabio,

Thank you for reaching out to us. As you see this falls under custom development which is regretfully outside the scope of our support, I could point you in the right direction with the understanding that it would ultimately be your responsibility to take it from here.

What you have in mind can be achieved with get_site_url() which retrieves the URL for a given site. You can refer to it’s documentation here http://developer.wordpress.org/reference/functions/get_site_url/

Hope this helps!

Hello @nabeel thank you for your reply

I’ve read this and hundreds of other pages, but truth is: I’m NOT a developer and I don’t know to write these. I assume it’s a simple task for a dev like you, so I would greatly appreciate if you could just re-write my rule on the original post, so it would work.

I’m sure this won’t take more than a few minutes of your life. Me, on the other hand, I’m searching for this at least for 100 hours and I can’t make it work. Please, it’s just about to re-write ONE single site URL. Please?

Just in case someone else needs this code, here’s the “solved” one. Took less than 5 minutes for a real dev to point me the right code:

add_action('check_admin_referer', 'logout_without_confirm', 10, 2);
function logout_without_confirm($action, $result)
{
	/**
* Allow logout without confirmation
	*/
	if ($action == "log-out" && !isset($_GET['_wpnonce'])) {
		$redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : get_home_url().'/?loggedout=true';
		$location = str_replace('&', '&', wp_logout_url($redirect_to));
		header("Location: $location");
		die;
	}
}

Cheers

Thanks for sharing!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.