Category slug $_SERVER[‘REQUEST_URI’];

I’m not sure whats wrong with this line. Have I place this incorrectly? How do I get it to recognize the $yourcat->slug;

 $cat = get_query_var('cat');
 $yourcat = get_category ($cat);
 $uri = $_SERVER['REQUEST_URI'];
 if (($uri == '/category/$yourcat->slug;') { 

Related posts

Leave a Reply

2 comments

  1. your syntax is wrong change the single quotation mark to a double quotation mark and remove the semicolom
    on this line:

    if (($uri == '/category/$yourcat->slug;') { 
    

    it should become:

    if (($uri == "/category/$yourcat->slug") {
    
  2. AND you can surround the variable with curly brackets

    if (($uri == "/category/{$yourcat->slug}") {
    

    when you use single quotes, php does not look in the string for variables to replace. when you use double quotes it does. But in some cases there can be confusion such as this case. So when you do object reference like this, it’s best to use the curly braces to explicitly say this is a variable that should be replaced.