This thread is over two years old and may be outdated. Please create a new thread if you need help, or email us if you have an active Premium license.

Replacing a function in child theme’s functions.php

Resolved 3 replies premiumthemetheme-vantage
11 years ago · Last reply by Greg Priday 11 years ago

Hi all,

In my child theme, I’m trying to have my childfunctions.php file replace some of the code from the Vantage theme’s functions.php file. How would I do that for this particular piece of code :

/**
 * Register widgetized area and update sidebar with default widgets
 *
 * @since vantage 1.0
 */
function vantage_widgets_init() {
	register_sidebar( array(
		'name' => __( 'Sidebar', 'vantage' ),
		'id' => 'sidebar-1',
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '',
		'after_title' => '',
	) );
	register_sidebar( array(
		'name' => __( 'Footer', 'vantage' ),
		'id' => 'sidebar-footer',
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '',
		'after_title' => '',
	) );
	register_sidebar( array(
		'name' => __( 'Header', 'vantage' ),
		'id' => 'sidebar-header',
		'before_widget' => '',
		'after_widget' => '',
		'before_title' => '',
		'after_title' => '',
	) );
}
add_action( 'widgets_init', 'vantage_widgets_init' );

I have tried using add_action and remove_action and obviously something’s amiss…

This is our free support forum. Replies can take several days.

Need fast email support? Get SiteOrigin Premium

Replies

3
  1. Greg Priday Staff 11 years, 5 months ago

    I should have made those functions pluggable, but there’s a work around for this. Disclaimer: I haven’t checked any of the following code.

    function vantage_child_init(){
        remove_action( 'widgets_init', 'vantage_widgets_init' );
    }
    add_action('init', 'vantage_child_init');
    function vantage_child_widgets_init() {
       // Your own stuff here
    }
    add_action( 'widgets_init', 'vantage_child_widgets_init' );

    Basically the problem is that the child theme’s functions.php is included before the parent theme’s functions.php. So if you call remove_action in the child theme, it needs to be at a point after the parent theme has added the action. Throwing it in an init function does the trick.

  2. Cedric Victor 11 years, 5 months ago

    And it works! Thank you for the quick response!

  3. Greg Priday Staff 11 years, 5 months ago

    Any time Cedric :)

Replies on this thread are closed.

Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Have a different question or issue?

Start New Thread