WordPress.org

Ready to get started?Download WordPress

Forums

removing an action in the child theme (2 posts)

  1. Adam
    Member
    Posted 1 year ago #

    I have a very basic, very confused question:

    if I do this in the parent theme's functions.php:

    function some_action(){
        do_action('some_action');
    }
    
    function print_hello(){
       echo "hello"
    }
    
    add_action('some_action','print_hello');
    
    some_action();
    
    //echos hello

    That's all fine and dandy. But if in the child theme's functions.php I do:

    require_once(TEMPLATEPATH . '/functions.php');
    var_dump(remove_action('some_action', 'print_hello')); exit;

    I get

    bool(false)

    Why?

    I recently wrote a test:

    if(has_action('some_action', 'print_hello')){
    		echo "true";
    	}else{
    		echo "action deos not exist";
    	}

    and got:

    action deos not exist

  2. Bob Gregor
    Member
    Posted 1 year ago #

    you need to add a hook to "after_setup_theme"

    ie:

    function demo_after_setup () {
    
    if(has_action('some_action', 'print_hello')){
    		echo "true";
    	}else{
    		echo "action deos not exist";
    	}
    }
    add_action('after_setup_theme', 'demo_after_setup");

    get rid of the REQUIRE_ONCE. That's not necessary after you add this hook, as WordPress as already done the require.

Topic Closed

This topic has been closed to new replies.

About this Topic