Skip to:
Content
Pages
Categories
Search
Top
Bottom

Overriding the themes function.php = blank page

  • @olivernielsen

    Participant

    When I copy the functions.php file from the parent theme to the child theme I’m developing, then my site both frontend and backend goes blank. Removing it from the child theme makes my site load again.

    Is this a bug or intended behaviour?

Viewing 13 replies - 1 through 13 (of 13 total)
  • @djpaul

    Keymaster

    What’s in your web server error log? I’m guessing a PHP duplicate function declaration warning.

    @olivernielsen

    Participant

    Nothing related to this in Apace, SQL, PHP logs. If I reproduce the problem, then nothing new turns up in those logs…

    I have tried emptying the file of code, and then the site loads. So it must be related to the code that’s in the BuddyPress standard theme.

    @djpaul

    Keymaster

    I’m almost certain you are getting a white page because, by copying parent theme functions.php into your child theme, you are re-declaring a function of the same name which PHP doesn’t like.

    AFAIK you don’t need to copy the functions.php into your child, that should be inherited. If you are trying to change a function which has been written into parent functions.php, you’ll need to approach it another way.

    @flynn

    Participant

    I had this problem adding extra site bar areas to the footer of my theme…

    It’s not perfect, but if you backup your functions.php to be safe, you can edit the parent functions.php

    Of course, this means that updates will erase your changes, so you’ll have to babysit any BP updates until a better solution is found.

    @takeo

    Participant

    Flynn… why not just register your extra widget areas in the child functions.php file? They should just be added to the already registered widget areas (sidebars) in the parent functions.php

    p.s. As to the original poster… ya… what Paul said. Two functions with the same name = white page.

    @rogercoathup

    Participant

    I’m also getting the white page… is my child functions.php read in addition to the parent functions.php (rather than simply replacing it), hence causing duplicate functions?

    @takeo

    Participant

    Yup. A child funcions.php file is the one file that will NOT override the parent file. It adds to it. So you have to make sure your functions have unique names.

    @technonow

    Member

    “make sure your functions have unique names”

    That’s the bit I don’t understand.

    I want to create an extra sidebar. The BuddyPress Default functions.php has

    register_sidebars( 1,

    array(

    ‘name’ => ‘Sidebar’,

    ‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’,

    ‘after_widget’ => ‘</div>’,

    ‘before_title’ => ‘<h3 class=”widgettitle”>’,

    ‘after_title’ => ‘</h3>’

    )

    );

    In my child theme I want to change the 1 to 2.

    I thought I’d still have to call the file in my child theme functions.php

    In my child Theme … Is it the functions.php file I have to rename, or is it that I need to change the name “Sidebar” or “Sidebars”

    Sorry for being so thick. I’m learning, but still beginning!

    @r-a-y

    Keymaster

    Rename “sidebar” to something else.

    @technonow

    Member

    I did say I was thick!

    I changed the original functions.php and added two new array under the existing one. One named Sidebar1 that I’d created and one named sidebar2 … when I swopped to child theme my site went blank.

    I then created a blank functions.php but just copied the following into it.

    array(

    ‘name’ => ‘Sidebar1’,

    ‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’,

    ‘after_widget’ => ‘</div>’,

    ‘before_title’ => ‘<h3 class=”widgettitle”>’,

    ‘after_title’ => ‘</h3>’

    )

    array(

    ‘name’ => ‘Sidebar2’,

    ‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’,

    ‘after_widget’ => ‘</div>’,

    ‘before_title’ => ‘<h3 class=”widgettitle”>’,

    ‘after_title’ => ‘</h3>’

    )

    That didn’t work, but at least the screen didn’t go blank! I know a little knowledge is dangerous, but I’m hoping I can learn by trial and error, so what has this thicko got completely wrong?

    @peterverkooijen

    Participant

    Yup. A child funcions.php file is the one file that will NOT override the parent file. It adds to it. So you have to make sure your functions have unique names.

    So you can move child specific functions to a file named functions.php in the child theme folder?

    Tried it. It works! Nice. I’m cleaning up my messy custom theme and this helps a lot.

    Thanks for the confirmation r-a-y!

    @r-a-y

    Keymaster

    Yes you can! Just make sure you name your own functions different than the parent theme’s functions.

    @paulhastings0

    Participant

    @technonow, At first I had the same problem that you are, a white screen. But I finally found a typo. Somehow I had entered a couple letters after a semicolon. Everything is now working fine for me now.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Overriding the themes function.php = blank page’ is closed to new replies.
Skip to toolbar