Detect the WordPress homepage

Post a reply


This question is a means of preventing automated form submissions by spambots.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

If you wish to attach one or more files enter the details below.

Maximum filesize per attachment: 1 MiB.

Expand view Topic review: Detect the WordPress homepage

Detect the WordPress homepage

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);

Top