Well, I decided to be smart and learn about how to create child themes instead of continuing to hack at Edu Clean. :D
For the most part, my baby steps have been wildly successful! But I'm having trouble with my child functions.php that I hope someone can shed some light on.
As I understand it, unlike my other child files, my child function.php will add to parent function.php rather than replace it (as with how a child footer.php would replace the parent footer.php).
My parent theme already has four widget areas. I want to add three more. I got it working when I placed my three new widget areas into parent function.php, and now I'm trying to move them into child function.php.
So far, I've tried doing this six different ways:
1. Placing just the code for my three new widgets into child function.php
2. Placing all of the original Register Widget code into child function.php
3. Place just the code for my three widgets, but wrapped in the same code that the original widgets are wrapped in:
function edus_widgets_init() {
global $bp_existed;
...
}
}
add_action( 'widgets_init', 'edus_widgets_init' );
And I tried each of these options wrapped in php tags, and without
All attempts give me an error: The code in child function.php appears in all its glory at the top of both my admin screen and my site. It ain't pretty.
I've read a few tutorials on working with child function.php, but have not found the guidance I need.
Well, I decided to be smart and learn about how to create child themes instead of continuing to hack at Edu Clean. :D
For the most part, my baby steps have been wildly successful! But I'm having trouble with my child functions.php that I hope someone can shed some light on.
As I understand it, unlike my other child files, my child function.php will add to parent function.php rather than replace it (as with how a child footer.php would replace the parent footer.php).
My parent theme already has four widget areas. I want to add three more. I got it working when I placed my three new widget areas into parent function.php, and now I'm trying to move them into child function.php.
So far, I've tried doing this six different ways:
1. Placing just the code for my three new widgets into child function.php
2. Placing all of the original Register Widget code into child function.php
3. Place just the code for my three widgets, but wrapped in the same code that the original widgets are wrapped in:
function edus_widgets_init() {
global $bp_existed;
...
}
}
add_action( 'widgets_init', 'edus_widgets_init' );
And I tried each of these options wrapped in php tags, and without
All attempts give me an error: The code in child function.php appears in all its glory at the top of both my admin screen and my site. It ain't pretty.
I've read a few tutorials on working with child function.php, but have not found the guidance I need.
Right now my child function.php is blank so as to avoid the error, but pasted below is one example of what I tried, the original widgets plus my three new footer widgets, wrapped in php tags:
But I get that error. I'm missing something else. I just don't know what it is.
(In the meantime, I've got "PHP for Dummies" on hold at the library. I also looked into a PHP class at the local college, but it's got two pre-requisites.)
There are so many ghosts of Marketpress wrecking havoc that David has suggested that I export my site and reinstall it in a different database. So that's my big project for today. I've just been working on the structure of my site, so there's very little actual content to export. Just a whooooollle lot of settings to redo.
After that, perhaps my child functions.php will work. I'll keep you posted!
Okay, I've moved my test site to a new test folder. Fresh installs of everything. It even has that new site smell.
But I'm still having the problem with my child function.php.
I begin and end with php tags, I changed the name of the function in both instances, and I include the original widget areas along with my three new footer widgets. Here is the code I'm using for the child function.php:
What am I missing? The parent works perfectly. The child prepends my admin screen and the site with the code itself. And nobody likes that.
Wait...does it have something to do with TEMPLATE_DOMAIN? Does it know to reach back to the parent? Do I need, I don't know, something like ../ before TEMPLATE_DOMAIN? I'm making wild guesses now.
8202 pointsLike some sort of WPMU DEV GodMindblowingly helpful memberLifetime member
WPMU DEV Fanatic
—
22nd November 2011 (6 months ago)
#
Hi Katy,
Working with Phil on this as I believe he'll be out for the day, I notice you've got <php at the top of this particular snippet, whereas it should be <?php.
I imagine that's why it's just outputting the bare code. Could you give that a go?
So, I got it working with the code in the child function.php. Phenomenal!
Then, I went back into the parent functions.php to remove another addition I had made:
`remove_action( 'bp_init', 'bp_em_init' );'
...which I had put in to remove the Events link in the BP profile. All it did was take me to my error page. This was yet another casualty of my database problems, or at least I think so, since the Events BP link works perfectly in my new install.
So I took it out...and White Screen of Death!
I thought to myself, surely I didn't just break my site by removing this one line of code that wasn't even supposed to be there in the first place! But it was true! I tried undoing the other function work I had just done -- all through my host of course -- I blanked out the child function.php, put my new widgets back in parent function.php. The Total White Death continued. I couldn't even access Pages. It was that bad.
I tried pasting in a fresh copy of function.php from a fresh download of Edu Clean. But all this freshity freshness amounted to nothing. Total Devastation.
I still couldn't believe that this crazy piece of workaround BP code made my whole site die. But, I put it back in, and it works! It's like a sword you can't remove or else the patient will bleed to death.
Meanwhile my new install's function.php works just fine without it, parent and child alike.
9603 pointsLike some sort of WPMU DEV GodMindblowingly helpful memberLifetime member
Sales & Support Pro
—
23rd November 2011 (6 months ago)
#
Hiya Katy,
Glad you got the child functions sorted (many thanks David for chipping in!)
It's likely that changing that line in itself didn't cause the white screen but prompted something else to happen.
Your best best is simply to re-upload the original theme files (download them from here again if you need to) in order to revert any changes you've made. Uploading will simply overwrite the edits you made (maybe take a backup first).
Responses (17)
Sales & Support Pro — 15th November 2011 (6 months ago) #
Can you paste the entire contents of your child functions.php please? Preferrably using pastebin.com
For your code to be showing up in the admin you must have something seriously wrong with your code.
Phil
Member — 15th November 2011 (6 months ago) #
Thanks Phil.
Right now my child function.php is blank so as to avoid the error, but pasted below is one example of what I tried, the original widgets plus my three new footer widgets, wrapped in php tags:
[Let's see if this embed from pastebin works...]
<script src="http://pastebin.com/embed_js.php?i=sXXkuh2b"></script>
Member — 15th November 2011 (6 months ago) #
[Maybe the iframe embed works?]
<iframe src="http://pastebin.com/embed_iframe.php?i=sXXkuh2b" style="border:none;width:100%"></iframe>
Member — 15th November 2011 (6 months ago) #
Nope. Okay, here's the link: http://pastebin.com/sXXkuh2b
And here's the paste:
<?php
function edus_widgets_init() {
global $bp_existed;
register_sidebar(array(
'name'=> __('Home Side Left', TEMPLATE_DOMAIN),
'id' => __('home-side-left', TEMPLATE_DOMAIN),
'description' => __('Home Side Left Widget', TEMPLATE_DOMAIN),
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
register_sidebar(array(
'name'=> __('Home Side Right', TEMPLATE_DOMAIN),
'id' => __('home-side-right', TEMPLATE_DOMAIN),
'description' => __('Home Side Right Widget', TEMPLATE_DOMAIN),
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
register_sidebar(array(
'name'=> __('Sidebar', TEMPLATE_DOMAIN),
'id' => __('sidebar', TEMPLATE_DOMAIN),
'description' => __('Sidebar Widget', TEMPLATE_DOMAIN),
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
if($bp_existed == 'true') {
register_sidebar(array(
'name'=> __('Member Sidebar', TEMPLATE_DOMAIN),
'id' => __('member-sidebar', TEMPLATE_DOMAIN),
'description' => __('Member Sidebar Widget', TEMPLATE_DOMAIN),
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
register_sidebar(array(
'name'=> __('Footer Left', TEMPLATE_DOMAIN),
'id' => __('footer-left', TEMPLATE_DOMAIN),
'description' => __('Footer Left Widget', TEMPLATE_DOMAIN),
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
register_sidebar(array(
'name'=> __('Footer Center', TEMPLATE_DOMAIN),
'id' => __('footer-center', TEMPLATE_DOMAIN),
'description' => __('Footer Center Widget', TEMPLATE_DOMAIN),
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
register_sidebar(array(
'name'=> __('Footer Right', TEMPLATE_DOMAIN),
'id' => __('footer-right', TEMPLATE_DOMAIN),
'description' => __('Footer Right Widget', TEMPLATE_DOMAIN),
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
}
}
add_action( 'widgets_init', 'edus_widgets_init' );
?>
Sales & Support Pro — 16th November 2011 (6 months ago) #
You've got an extraneous curly brace on line 75 (in the pastebin). That's probably the cause.
Phil
Member — 16th November 2011 (6 months ago) #
Hmmm...the original parent function.php had that extra curly bracket as well.
But I tried taking it out.
Now my admin screen and my site are gone -- white screen.
I'll go into my host to empty that file again.
What can I try next?
Thank you!
Sales & Support Pro — 17th November 2011 (6 months ago) #
Ah my mistake, that curly brace should be there - I'd missed the IF statement.
Can you change the function name from edus_widgets_init to something (anything) else please?
Phil
Member — 17th November 2011 (6 months ago) #
Hi Phil,
I changed it to edu_child_widgets_init
And....the top of my admin screen now shows...well, I'll show you...
Maybe I'm supposed to change the function name somewhere else too? Sorry, I know very little php.
Thanks!
Katy
Sales & Support Pro — 18th November 2011 (6 months ago) #
Did you also change the reference to the function in the add_action? I.e. this bit;
add_action( 'widgets_init', 'edus_widgets_init' );Phil
Member — 18th November 2011 (6 months ago) #
I changed:
function edus_widgets_init() {to:
function edus_child_widgets_init() {and:
add_action( 'widgets_init', 'edus_widgets_init' );to:
add_action( 'widgets_init', 'edus_child_widgets_init' );But I get that error. I'm missing something else. I just don't know what it is.
(In the meantime, I've got "PHP for Dummies" on hold at the library. I also looked into a PHP class at the local college, but it's got two pre-requisites.)
Sales & Support Pro — 21st November 2011 (6 months ago) #
You definitely have <?php and ?> at the beginning and end of your file?
Member — 21st November 2011 (6 months ago) #
Yes.
There are so many ghosts of Marketpress wrecking havoc that David has suggested that I export my site and reinstall it in a different database. So that's my big project for today. I've just been working on the structure of my site, so there's very little actual content to export. Just a whooooollle lot of settings to redo.
After that, perhaps my child functions.php will work. I'll keep you posted!
Member — 22nd November 2011 (6 months ago) #
Okay, I've moved my test site to a new test folder. Fresh installs of everything. It even has that new site smell.
But I'm still having the problem with my child function.php.
I begin and end with php tags, I changed the name of the function in both instances, and I include the original widget areas along with my three new footer widgets. Here is the code I'm using for the child function.php:
What am I missing? The parent works perfectly. The child prepends my admin screen and the site with the code itself. And nobody likes that.
Wait...does it have something to do with TEMPLATE_DOMAIN? Does it know to reach back to the parent? Do I need, I don't know, something like ../ before TEMPLATE_DOMAIN? I'm making wild guesses now.
WPMU DEV Fanatic — 22nd November 2011 (6 months ago) #
Hi Katy,
Working with Phil on this as I believe he'll be out for the day, I notice you've got <php at the top of this particular snippet, whereas it should be <?php.
I imagine that's why it's just outputting the bare code. Could you give that a go?
-David
Member — 22nd November 2011 (6 months ago) #
Gah! Facesmack! How could I have missed something so obvious? I must have been trying too hard!
THANK YOU as always for the education!! It works! You're the best!
Member — 22nd November 2011 (6 months ago) #
Want to hear something really weird?
So, I got it working with the code in the child function.php. Phenomenal!
Then, I went back into the parent functions.php to remove another addition I had made:
`remove_action( 'bp_init', 'bp_em_init' );'
...which I had put in to remove the Events link in the BP profile. All it did was take me to my error page. This was yet another casualty of my database problems, or at least I think so, since the Events BP link works perfectly in my new install.
So I took it out...and White Screen of Death!
I thought to myself, surely I didn't just break my site by removing this one line of code that wasn't even supposed to be there in the first place! But it was true! I tried undoing the other function work I had just done -- all through my host of course -- I blanked out the child function.php, put my new widgets back in parent function.php. The Total White Death continued. I couldn't even access Pages. It was that bad.
I tried pasting in a fresh copy of function.php from a fresh download of Edu Clean. But all this freshity freshness amounted to nothing. Total Devastation.
I still couldn't believe that this crazy piece of workaround BP code made my whole site die. But, I put it back in, and it works! It's like a sword you can't remove or else the patient will bleed to death.
Meanwhile my new install's function.php works just fine without it, parent and child alike.
So weird.
Sales & Support Pro — 23rd November 2011 (6 months ago) #
Hiya Katy,
Glad you got the child functions sorted (many thanks David for chipping in!)
It's likely that changing that line in itself didn't cause the white screen but prompted something else to happen.
Your best best is simply to re-upload the original theme files (download them from here again if you need to) in order to revert any changes you've made. Uploading will simply overwrite the edits you made (maybe take a backup first).
Thanks
Become a member