- This topic has 21 replies, 2 voices, and was last updated 7 years, 9 months ago by
Tom.
-
AuthorPosts
-
May 9, 2018 at 8:32 pm #571987
Sami
Hello, and sorry for bothering you guys, the issue i am having is totally my bad!
I had a developer to write some custom code for me as i am new to building websites. The custom code was added to the parent theme and as the theme was updated all the custom code was wiped off.I have since done some searching and understand that custom code should be added to the child theme.
I was smart enough to create a back up of the code and i am pretty sure i know where all the custom code is.I tried to create js, css and php files and i think everything else worked out except the functions file that i added to the child seems to break the website if i add the custom code in the file manager.
If i add it to the appearance –> editor then it gives me this error.
Your PHP code changes were rolled back due to an error on line 138 of file wp-content/themes/generatepress/functions.php. Please fix and try saving again.
Cannot redeclare woocommerce_custom_template_loop_product_link_open() (previously declared in wp-content/themes/generatepress-child/functions.php:55)
Any advise is highly appreciated.
May 9, 2018 at 9:04 pm #572019Tom
Lead DeveloperLead DeveloperWhat that error means is you’ve previously declared that exact same function name in your child theme.
Search for
woocommerce_custom_template_loop_product_link_openwithin the editor, and make sure only one function exists with that name.Let me know if you need more info 🙂
May 9, 2018 at 9:29 pm #572028Sami
Sorry, i don’t quite understand what i am supposed to do.
I used ctl + f and found 2 instances where woocommerce_custom_template_loop_product_link_open is used.
function woocommerce_custom_template_loop_product_link_open() { global $product; $link = apply_filters( 'woocommerce_loop_product_link', get_the_permalink(), $product ); echo '<a target="_blank" href="' . esc_url( $link ) . '">'; }&
add_action('woocommerce_before_shop_loop_item',function(){ global $product; if($product->get_type() == 'external'){ remove_action('woocommerce_before_shop_loop_item','woocommerce_template_loop_product_link_open'); add_action('woocommerce_before_shop_loop_item','<strong>woocommerce_custom_template_loop_product_link_open</strong>',5); add_filter('woocommerce_loop_product_link',function($product_link,$product){ return $product->get_product_url(); },3,2); }I can give you access to the editor too if want and you can fix it easily that way and i won’t be stealing your time.
May 10, 2018 at 9:04 am #572518Tom
Lead DeveloperLead DeveloperWhat’s on line 55 of your child theme functions.php file?
May 10, 2018 at 9:00 pm #572935Sami
Thanks for your response
line 55: global $product;
May 10, 2018 at 9:03 pm #572939Tom
Lead DeveloperLead DeveloperAh, then the code has changed since the error you shared happened.
Feel free to send me temp login details and I’ll take a look: https://generatepress.com/contact/
May 10, 2018 at 9:24 pm #572948Sami
Sent the login info!
May 13, 2018 at 10:04 pm #574783Sami
Hello Tom, did you get my login details? Do you need me to provide some additional info?
Thanks, Aleksi
May 14, 2018 at 8:53 am #575302Tom
Lead DeveloperLead DeveloperI replied to your email a few days ago.
I checked your child theme functions.php and there was barely anything in there. Did you remove all of your custom code?
May 14, 2018 at 9:14 am #575324Sami
Oh yeah, sorry i gave a different email so i didn’t check that one.
Yeah i couldn’t submit the code because of the error. The custom code is all in the parent theme functions file.
I just tried to copy that same custom code to the child theme. You can check the parent theme, it’s all there.
Thanks for helping out.
May 14, 2018 at 8:24 pm #575735Tom
Lead DeveloperLead DeveloperCan you share the exact code you’re adding into the child theme inside a pastebin?: https://pastebin.com/
Then I’ll be able to inspect it and make any necessary edits 🙂
May 14, 2018 at 9:24 pm #575768Sami
pastebin.com/ABtuYB75
I am not a 100% of what the exact code is. My programmer added the code to the parent theme. So everything that is not part of the normal GP code in the parent functions.php is custom code i think. So i just basically copied the whole thing after the basic generate press code.
All the custom code have a //txt before explaining what it does.
May 15, 2018 at 9:04 am #576226Tom
Lead DeveloperLead DeveloperI couldn’t really spot anything wrong, but maybe try this: https://pastebin.com/eKYaKRDT
May 15, 2018 at 10:17 am #576334Sami
Got this message now.
Your PHP code changes were rolled back due to an error on line 199 of file wp-content/themes/generatepress/functions.php. Please fix and try saving again.
Cannot redeclare the_excerpt_max_charlength() (previously declared in wp-content/themes/generatepress-child/functions.php:105)
Got this message now.
Can i remove all the custom code from the parent theme?
Maybe it is not working because i have the same custom code in child and parent now.
If you want to take a look you can use the login credentials i submitted before and see if you can make sense of it.
May 15, 2018 at 8:46 pm #576683Tom
Lead DeveloperLead DeveloperAh yes, you need to remove all of the custom code from the parent theme before you add it to the child theme.
-
AuthorPosts
- You must be logged in to reply to this topic.