Updating Child Theme

I need to add code to my functions.php file because every time X is updated, I need to change the functions.php file. I understand that I need to update a child theme.

When I go to the dashboard and view the active themes (Appearance > themes), I see that there is already an active X child theme? (Please see red circle on attached image.) Do I update this one? If so, where do I add the functions.php code? I clicked customize and I only see where to add CSS code.

Also, please see the green circle on the attached image. This looks like the X theme but why does it say Activate when the X theme is already activated?

PLEASE, PLEASE, PLEASE help.

Hi There @eutaw

Thanks for writing in! I see that you already have an active child theme. To add a code into your child theme’s functions.php file, first open your functions.php file using a text editor which is located under
/wp-content/themes/x-child/functions.php

Then you can simply add your customizations into your functions.php file and upload it to the same location to get affected.

Hope that’s clear.

I changed the functions.php file for x-child by going to the server and changing this file: /wp-content/themes/x-child/functions.php. Before changing this file, I copied it to a file named functionsold.php so that I could preserve the file. Then I added my code to the bottom of the functions.php file and I got the following error.

Fatal error: Cannot redeclare mycustom_wp_footer() (previously declared in /home1/friengs6/public_html/wp-content/themes/x-child/functions.php:30) in /home1/friengs6/public_html/wp-content/themes/x/functions.php on line 260

Did I update the correct functions.php file? By the way, the reason I decided to update the child theme is because I added this code to the functions.php file that’s under x theme and the code isn’t executing as in the past. I really need to have this code execute immediately. Thanks for any help on this.

Hi Eutaw,

The reason for the child theme is so you don’t touch anything on the parent theme, you can modify or add functionalities to the parent theme through its child. This way when the parent theme updates, your modification will stay because it was safe on the child theme.

The child theme is for you to develop, expand, modify, and add new functionalities if you needed to.

Child Themes
How To Setup Child Themes
Customizations - Best Practices

That error you posted above shows that you added the function twice, you added it on the parent X theme functions.php file (/themes/x/functions.php), and you also added it on the child theme’s functions.php file (/themes/x-child/functions.php)

Please remove the one you added on the parent, and keep only on the child theme.

Hope it helps,
Cheers!

Just to be certain, I do update the functions.php file that is located on my server (Bluehost), correct?

Yes, the functions.php file is in your server. Please edit as @friech has shown.

Thanks.

There must be another reason why my contact form 7 is not linking to PayPal any longer. I have moved the code to the end of the child theme and still no execution of the code. Before I installed the latest version of X, and when the code was in functions.php of the X theme, everything worked well. But after installing the latest version of X theme, code is not being executed in either functions.php file. PLEASE HELP!!!

Another question…why isn’t X theme shown as being active under Appearance>themes?

Hey @Eutaw,

The X theme is still in Appearance > Themes. It is not active because you are using X Child Theme. The child theme inherits all the features of the parent X theme.

I have check your contact form and as soon as you submit it, there is a JS error:

Uncaught SyntaxError: Unexpected token : (index):667 

This came from the JS code which you have added in the functions.php

add_action( 'wp_footer', 'mycustom_wp_footer' );
 
function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
    if ( '926' == event.detail.contactFormId ) {
        location = https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=treasurer%40nc%2dabl%2eorg&lc=US&amount=75%2e00&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted';
    }
}, false );
</script>
<?php
}

Please double check the Paypal location url. It seems that there are invalid characters in it which created this issue.

Please let us know how it goes.

Thank you. I found the problem. Again, thanks.

We are delighted to assist you with this.

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.