Search code examples
wordpressurlstrpos

Check wordpress url begins with certain string


if (strpos($_SERVER['REQUEST_URI'], "/arr/") !== false) {

}

I tried with the above condition.

http://localhost/wordpress/arr/ => executed

http://localhost/wordpress/arr/sample-page/ => not executed

I want to execute it for the second one as well.

Please advise.

Thanks.


Solution

  • This may be a solution:

    $paths = explode('/', $_SERVER['REQUEST_URI']);
    
    foreach($paths as $path){
    if($path=='arr')
    {
    /*Do what you need*/
    }
    }