I am passing some variables to some (wordpress) work as following:


Rather than hard coded values for exclude (ie. 4,7), I wish to pass a flexible inside it.

I'm trying following but getting syntax error.

$exclude = 4;
wp_list_categories('exclude='.<?php echo $exclude; ?> .'&title_li=');

Are you able to help fixing it? Thanks.

You're already inside PHP code, so not wrap the $exclude in <?php ?>

wp_list_categories('exclude='. $exclude .'&title_li=');

Better still, you are able to surround the entire factor in double quotes to interpolate $exclude inside the relaxation from the string.


The above mentioned solutions are obviously correct, however i won't assist but question why you would like to pass a string for the reason that way. I'm mentioning that you're hard-coding the 'exclude=' and '$title_li=' components in to the function argument, once they should most likely get their very own variable names if you are planning to create different types of category demands. What i'm saying:

$category = '4'
$head = 'exclude';
$foot = '$title_li='

The simplest change could be this

wp_list_categories('exclude=' . $exclude . '&title_li=');

Alternatively, you should use double quotes then encase the variables in - generally, I favor to avoid this because it causes it to be slightly less apparent what you are doing, instantly.