Site logo

Archived topic

Lost custom code with update.

21 replies · Started by Sami on May 9, 2018

Viewing posts 1–15 of 22

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.

What 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_open within the editor, and make sure only one function exists with that name.

Let me know if you need more info :)

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.

What's on line 55 of your child theme functions.php file?

Thanks for your response

line 55: global $product;

Sent the login info!

Hello Tom, did you get my login details? Do you need me to provide some additional info?

Thanks, Aleksi

I 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?

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.

Can 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 :)

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.

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.

Ah yes, you need to remove all of the custom code from the parent theme before you add it to the child theme.

This archived topic is closed to new replies.