Getting the sub folder install location for WordPress if its not installed in the site root
Simple home_url() method
wp_redirect( home_url( '/' ) );
//wp_redirect( home_url( '/my_page_name' ) ); //If you want to redirect to a specific page
die();
Getting it in code
//Get WordPress sub folder path if its not instlaled on the site root
$SiteUrl = get_site_url();
$ParsedUrl = parse_url($SiteUrl);
$WordpressInstallSubPath = trim($ParsedUrl['path'] ?? '', '/'); //Trim leading/trailing slashes and return full path (if any)
if (strlen($WordpressInstallSubPath) > 0)
$WordpressInstallSubPath = '/' . $WordpressInstallSubPath;
//Install URL $WordpressInstallSubPath
//https://example.com '' (empty — root)
//https://example.com/wordpress '/wordpress'
//https://example.com/blog/wp '/blog/wp'
//https://example.com/a/b/c '/a/b/c'
