Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I just noticed, in a theme file, I can access custom functions I add to my functions file, however I can NOT access variables I set in my functions file.

I have a few variables I set inside my functions.php file for example...

$feedburnerUsername = 'username';

Now in my sidebar.php file If I try to access this variable, it is not available, how can I make it available?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

Whilsts @Shaon's answer is perfectly valid, I'm of the opinion you really shouldn't be throwing configuration settings around as global variables - use a constant instead.

/* Constants are in the global scope, but can only be defined once. */
define( 'FEEDBURNER_USERNAME', 'my_username' );
define( 'FEEDBURNER_PASSWORD', 'my_password' );

If the variable needs to be dynamic (for example, if it's an option in the database), use a function that returns it:

function get_feedburner_config( $option = null )
{
    $config = get_option( 'feedburner' );
    $config = wp_parse_args( $config, array(
        'username' => 'default',
        'password' => 'default'
    ));

    if ( $option )
        return isset( $config[ $option ] ) ? $config[ $option ] : '';

    return $config;
}
share|improve this answer
add comment

use

global $feedburnerUsername; 

at the top of functions.php

and when you will start using it to another scope, like another file or function, write

global $feedburnerUsername; 

again before use

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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