Problem redeclaring funtion in functions.php in a child theme
-
Hi,
I have been looking for a solution here but couldn’t find it. If I missed it I apologize and please redirect me to it.
First let me say that I am new to WP and PHP so may be the question is stupid and the solution is simple but I can’t figure it out.
Here is my problem:
I am trying to create a child theme based on Twenty Eleven Theme. I need to change twentyeleven_continue_reading_link() function. I know that the most simple way is to change the function in the twentyeleven\functions.php but it’s not good solution since when twentyeleven is updated the changes will be lost. So I decided to try to overwrite it.
Here is the child theme’s functions.php code<?php if (!function_exists('twentyeleven_continue_reading_link')){ function twentyeleven_continue_reading_link() { return ' <a href="'. esc_url( get_permalink() ) . '">' . __( '<span class="meta-nav">>> </span> прочети', 'twentyeleven' ) . '</a>'; } } ?>
When I run it I get the following error: ” Cannot redeclare twentyeleven_continue_reading_link() (previously declared in wp-content\themes\sharko\functions.php:12) in \wp-content\themes\twentyeleven\functions.php on line 328″
I read that child theme’s functions.php is loaded first and this allows a function to be replaced. Can someone clarify that for me?
Is it possible that the system checks if the twentyeleven_continue_reading_link() function exists and since it doesn’t it declares it but when functions.php from the parent theme is loaded it tries to declare it again and that’s why it gives the error?
I am opened to any suggestions for a solution.Thank you!
- The topic ‘Problem redeclaring funtion in functions.php in a child theme’ is closed to new replies.