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'm going to build my first Child Theme. I understood how to override functions (hope!), but how to override variables? For example, in a Premium Template I want to change the values of feed variables shown in functions.php:

$app_rss_feed = 'http://xxx.rss';
$app_twitter_rss_feed = 'http://yyy.rss';
$app_forum_rss_feed = 'http://zzz.rss';

But if I create my functions.php file inside my child theme and assign a different RSS feed value to these variables... nothing happens. So, which is the right way to change variables?

share|improve this question
    
are those variables inside a function? –  Bainternet Mar 23 '12 at 22:37
    
the variables are outside any function. Are declared inside the functions.php of the theme. –  Avionicom Mar 24 '12 at 11:38
add comment

2 Answers

up vote 3 down vote accepted

I'm mobile, so this will be short.

Use the after_setup_theme hook to add a function to set those variables. Declare them as global inside that function before setting them.

Hope that helps.

If anybody wants to add an example to this answer before I get home, feel free. ;)

share|improve this answer
1  
Thank you for the answer. I've done as you suggested and it works: function the_theme_setup(){ global $app_rss_feed, $app_twitter_rss_feed, $app_forum_rss_feed; $app_rss_feed = 'xxx.rss'; $app_twitter_rss_feed = 'yyy.rss'; $app_forum_rss_feed = 'zzz.rss'; } add_action( 'after_setup_theme', 'the_theme_setup' ); Is it correct? –  Avionicom Mar 24 '12 at 12:48
add comment

The parent theme’s functions.php is loaded later, it will overwrite those variables. Show us the code where these variables are declared and where thex are used, there may be a filter you could use.

An example: In fetch_feed() you can filter the feed URL:

do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) );

To filter the values, you could check for the parent theme’s URL:

add_filter( 'wp_feed_options', 'wpse_46644_feed' );

function wpse_46644_feed( $arr )
{
    if ( 'http://example.com/feed/' === $arr[1] )
    {
        $arr[0]->set_feed_url( 'http://replacement.example.com/feed/' );
    }
}

Not tested, just an idea.

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.