• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

RESOLVED Fatal error: Cannot redeclare function

wertykid

New member
Messages
1
Likes
0
Points
1
#1
Hello,

I am encountering this issue when I add a snippet into my product page. It can run everywhere on the site, when I change it to a shortcode it does not work anymore. Can anybody help me with this? Thank you!

Fatal error: Cannot redeclare cfwc_save_custom_field_basic() (previously declared in /plugins/insert-php/includes/shortcodes/shortcode-php.php(45) : eval()'d code:21) in /plugins/insert-php/includes/shortcodes/shortcode-php.php(45) : eval()'d codeon line 26
 
Last edited:

Kirill

Support team
Messages
82
Likes
4
Points
8
#2
Hi

As indicated in the error, function cannot be redeclared with the same name.
This can happen, for example, if you create a function in your snippete code and then insert this snippet several times on the page.
You can avoid this error by wrapping function declaration in conditional block.

Example:
PHP:
if (! function_exists ('cfwc_save_custom_field_basic')) {

    function cfwc_save_custom_field_basic () {

        // code here

    }

}
// usage example
cfwc_save_custom_field_basic();
If this case does not suit you. Please send your snippet code that I could help you.

Best regards, Kirill
Webcraftic team