Thursday, November 10, 2022

Detect current URL and match with home page in wordpres

Detect current URL and match with home page in wordpres:

Sometimes you may select "Your latest posts" in backend settings->reading.

In this case your home page will be your theme's index.php file.

In this case you might need to detect what is your front page / home page and match to your current page.

In this case you can use below code to differentiate home page to other pages/posts:

$home_url = get_option('home') . '/';
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'
? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

if ($home_url === $actual_link) {
    // Code goes here
}

// Happy coding...

Switch PHP version in Ubuntu OS or Zorin OS

First check where is installed your PHP by the below command: $ which php See PHP version by below command: $ php -v As I've installed P...