wordpress: how to check if the slug contains a specific word? wordpress: how to check if the slug contains a specific word? wordpress wordpress

wordpress: how to check if the slug contains a specific word?


Using PHP:

$url = $_SERVER["REQUEST_URI"];$isItBlog = strpos($url, 'blog');$isItNews = strpos($url, 'news');if ($isItBlog!==false){    //url contains 'blog'}if ($isItNews!==false){    //url contains 'news'}

http://www.php.net/manual/en/function.strpos.php


slugContainsBlog = "blog"if(window.location.href.indexOf(slugContainsBlog) > -1) {   //Contains Blog}slugContainsNews = "news"if(window.location.href.indexOf(slugContainsNews) > -1) {   //Contains News}

Here is a javascript version.

You can learn more about indexOf here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf