by axew3 » Fri Mar 04, 2022 6:02 pm
To detect always, using any permalink, into any stack point, if we are into WordPress homepage, this is the way
( also answered here, because others are all wrongs and there is no answer/solution over all internet (almost for what i have find out):
https://stackoverflow.com/questions/492 ... 3#71355373 )
Code: Select all
if(!empty($_SERVER['REQUEST_URI']))
{
if(substr($_SERVER['REQUEST_URI'], -1, 1) == '/'){
$REQUEST_URI = substr($_SERVER['REQUEST_URI'], 0, -1);
}
$siteUrl = get_option('siteurl');
if(substr($siteUrl, -1, 1) == '/'){
$siteUrl = substr($siteUrl, 0, -1);
}
if(!empty($REQUEST_URI)){
$r = strpos($siteUrl, $REQUEST_URI);
if($r !== false)
{ $HOMEPAGE = true; }
} elseif ( $_SERVER['REQUEST_URI'] == '/' OR empty($REQUEST_URI) ){ $HOMEPAGE = true; }
}
var_dump($HOMEPAGE);
To detect always, using any permalink, into any stack point, if we are into WordPress homepage, this is the way
( also answered here, because others are all wrongs and there is no answer/solution over all internet (almost for what i have find out): https://stackoverflow.com/questions/4920736/what-are-the-different-ways-to-detect-home-page-in-wordpress/71355373#71355373 )
[code]if(!empty($_SERVER['REQUEST_URI']))
{
if(substr($_SERVER['REQUEST_URI'], -1, 1) == '/'){
$REQUEST_URI = substr($_SERVER['REQUEST_URI'], 0, -1);
}
$siteUrl = get_option('siteurl');
if(substr($siteUrl, -1, 1) == '/'){
$siteUrl = substr($siteUrl, 0, -1);
}
if(!empty($REQUEST_URI)){
$r = strpos($siteUrl, $REQUEST_URI);
if($r !== false)
{ $HOMEPAGE = true; }
} elseif ( $_SERVER['REQUEST_URI'] == '/' OR empty($REQUEST_URI) ){ $HOMEPAGE = true; }
}
var_dump($HOMEPAGE);[/code]