Trying to obtain the page url with the following code prior to Wordpress 6.0 works, but after update to Wordpress 6.0, $wp->request
is coming through as an empty string on all pages. I have Post name set in permalinks under Common Settings if that matters.
The code below no longer works for getting the current url in the browser:
add_query_arg($wp->query_vars, $wp->request);
If there a new way to obtain the current url in the browser with Wordpress 6.0? I would need to obtain it as early as possible. The code above worked as is directly within the functions.php file without any hooks. Is there something similar to this in Wordpress 6.0?
EDIT: Tested with a Fresh install of Wordpress 6.0
This is also happening after installing a Fresh copy of Wordpress 6.0 in the twentytwentytwo theme functions.php file (placed the following at the top of the file):
global $wp;
$current_url = add_query_arg($wp->query_vars, $wp->request);
error_log(var_export($current_url, true));
error_log(var_export($wp->request, true));
Look at wp-content/debug.log
and see that both are empty strings no matter what url you go to on the site, or what your permalink settings are set to. Obviously, you will need to enable the debug log in wp-config.php first.
What is the correct way in Wordpress to obtain the current page url?
$wp->request
code is running in a classicadmin-ajax.php
handler, but AJAX handlers don't have favicons and images, are you actually running this on the frontend then sending it to an AJAX handler? Please provide more context for what you're doing and more code for what surrounds this, as well as how and where you are processing it. There's a very strong possibility that you've built something in a way that has a much simpler alternative, or that you're hiding key information that you don't think is relevant to keep it super abstract/generic