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.
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.
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'.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With