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?

  • 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

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. ;)

  • 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

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.

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.