• TIP FOR THEME DEVELOPERS. The fact that a child theme’s functions.php is loaded first means that you can make the user functions of your theme pluggable —that is, replaceable by a child theme— by declaring them conditionally. E.g.:

    if ( ! function_exists( ‘theme_special_nav’ ) ) {
    function theme_special_nav() {
    // Do something.
    }
    }
    In that way, a child theme can replace a PHP function of the parent by simply declaring it beforehand.

    I read this on wordpress talking about child themes (http://codex.wordpress.org/Child_Themes), but I don’t understand it.

    How does declaring a function in your child theme replace a php function of the parent? If the parent loads second, would not the child function with the same name just be overridden? How does PHP handle functions being declared twice like that?

    Thanks for the help!

  • The topic ‘Declaring a function twice – how does this work? Child Theme/Parent Theme’ is closed to new replies.