please forgive me I'm relatively new to PHP...
I would like to create a shortcode called [city-name] and have tried placing the following code in my functions.php file:
function get_city_name() {
return $current_cityinfo['cityname'];
}
add_shortcode( 'city-name', 'get_city_name' );
Then entered the [city-name] shortcode into a page to test and there is no luck...
Is there something wrong with my syntax.... I have entered the following into my category pages and that works absolutely fine:
<h1 class="loop-title"><?php single_cat_title(); ?> - <?php echo $current_cityinfo['cityname'];?></h1>
I hope someone can help me out here... been searching for over 2 hrs now and no luck so thanks in advance!
JAke
$current_cityinfo
insideget_city_name()
, before you can use it - it is a PHP scope problem, read up on it. If it is aglobal
variable, then do it by using the key word. Otherwise you have to use whatever logic is behind the variable.