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

梦想与她 提交于 2019-12-04 07:31:22

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!