Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

wordpress

slug

I'm trying to use a conditional statement to check if either of two words (blog & news) appear in the slug. If one shows up I will display one menu, if the other then its corresponding menu shows.

like image 246
Andy Avatar asked Nov 28 '11 15:11

Andy


People also ask

What is category slug in WordPress?

What is a Slug? A WordPress slug is nothing more than a few words, which you choose, to describe a post, page, category, or tag within WordPress. These words then appear as part of the URL (or Permalink) directing visitors to that content.

What is slug tag?

A slug is the part of a URL that identifies a particular page on a website in an easy-to-read form. In other words, it's the part of the URL that explains the page's content. For this article, for example, the URL is https://yoast.com/slug, and the slug simply is 'slug'.


1 Answers

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

like image 156
totallyNotLizards Avatar answered Nov 15 '22 14:11

totallyNotLizards