Cannot redeclare function
-
Thanks for the excellent plugin.
I am trying to use some code from WPBeginner. It defines the same function in two different ways depending on whether a cookie is set or not. So logically the function cannot get declared twice. In essence the code is:
function wpb_cookies_tutorial2() { if(isset($_COOKIE['wpb_visit_time'])) { function visitor_greeting() {} } else { function visitor_greeting() {} } }
When I try to activate this I get:
Snippet automatically deactivated due to an error on line 6: Cannot redeclare function visitor_greeting.If I try:
function wpb_cookies_tutorial2() { if(isset($_COOKIE['wpb_visit_time'])) { if (!function_exists('visitor_greeting')){ function visitor_greeting() {} } } else { if (!function_exists('visitor_greeting')){ function visitor_greeting() {} } } }
then Code Snippets accepts the code.
Is that the best way to make it acceptable to Code Snippets?
The page I need help with: [log in to see the link]
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.