akarimov Posted October 16, 2011 Share Posted October 16, 2011 I got the following code. I need to insert a "get_footer();" tag, but the code won't run. How do I code insert it properly? $random_password = wp_generate_password( 12, false ); $status = wp_create_user( $username, $random_password, $email ); if ( is_wp_error($status) ) echo "Username already exists. Please try another one."; ---------------------------------INSERT get_footer(); HERE.------------------------------------------- else { $from = get_option('admin_email'); $headers = 'From: '.$from . "\r\n"; $subject = "Registration successful"; $msg = "Registration successful.\nYour login details\nUsername: $username\nPassword: $random_password"; wp_mail( $email, $subject, $msg, $headers ); echo "Please check your email for login details."; get_footer(); } Quote Link to comment https://forums.phpfreaks.com/topic/249191-proper-coding-grammar/ Share on other sites More sharing options...
MasterACE14 Posted October 16, 2011 Share Posted October 16, 2011 if ( is_wp_error($status) ) { echo "Username already exists. Please try another one."; get_footer(); } Quote Link to comment https://forums.phpfreaks.com/topic/249191-proper-coding-grammar/#findComment-1279667 Share on other sites More sharing options...
jcbones Posted October 16, 2011 Share Posted October 16, 2011 I suppose this is for wordpress? Does the footer.php file exist in your theme directory? Have you tried moving the get_footer() function BELOW the else statement? Quote Link to comment https://forums.phpfreaks.com/topic/249191-proper-coding-grammar/#findComment-1279668 Share on other sites More sharing options...
akarimov Posted October 16, 2011 Author Share Posted October 16, 2011 get_footer() statement is in multiple place in that code, and it works fine. When I try to put get_footer() under echo "Usern ... her one." line - it gives me an error. and yes, this is for wordpress I need get_footer() to run under first condition, and it okay under second condition. Quote Link to comment https://forums.phpfreaks.com/topic/249191-proper-coding-grammar/#findComment-1279712 Share on other sites More sharing options...
jcbones Posted October 16, 2011 Share Posted October 16, 2011 MasterACE's solution will work. My suggestion is that you don't need to run get_footer() in every different senerio on the page. Rather, run it at the bottom of the page, as it is served no matter what. If there is ever a function that you must include in every if/else statement, putting it below all of the statements will get the same effect, but with less code. Quote Link to comment https://forums.phpfreaks.com/topic/249191-proper-coding-grammar/#findComment-1279823 Share on other sites More sharing options...
MasterACE14 Posted October 18, 2011 Share Posted October 18, 2011 My suggestion is that you don't need to run get_footer() in every different senerio on the page. Rather, run it at the bottom of the page, as it is served no matter what. If there is ever a function that you must include in every if/else statement, putting it below all of the statements will get the same effect, but with less code. that is a far better solution. Rather than the 'quick fix'. Quote Link to comment https://forums.phpfreaks.com/topic/249191-proper-coding-grammar/#findComment-1280101 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.