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;') { 

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") {

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.