I'm working on a wordpress plugin and am running into an inssue with get_option( 'home' ).

What I'm trying to do: if the user (or admin) is not logged in then a login form will appear on a custom page I've built (from the plugin). I had tried doing this from scratch but everything I was finding was telling how to do it from in the root theme folder... if anyone can help me do this (from scratch) from within a plugin I'm willing to try!

Here is my source code...

<?php get_header(); ?>

<div id="content" class="inner">

    <div class="full shadow photo-uploadr">

        <div class="pad">

           <?php if ( is_user_logged_in()) { ?> 

            <?php } else { ?>

                <!-- BEGIN #login_form -->              
                <form name="loginform" id="login_form" class="login_form wpcf7-form" action="<?php get_option( 'home' ); ?>/wp-login.php" method="post">

                        <input type="text" name="log" id="user_login" class="input" placeholder="Username" />

                        <input type="password" name="pwd" id="user_pass" class="input" placeholder="Password" />

                    <button name="wp-submit" id="wp-submit" class="btn wpcf7-submit"><?php _e("Sign in", "shorti"); ?></button>

                <!-- END #contact_form -->

            <?php } ?>




<?php get_footer(); ?>

This is from a custom page template file that the plugin has created.

The problem I'm having is when I go to sign in I'm redirected to a 404 error page saying, "url can't be found"... the reason for this is that it's only looking for /wp-login.php. I'm new to working with plugins... so it might be just a simple path defining issue or something noobish like that.

My plugin folder looks something like this: photo-uploadr (main folder)/photo-uploadr.php (main file)/templates (secondary folder)/custom-uploadr.php (file with issue)

Thanks & if you see anything that might not be best practice, let me know. ;)

  • You're new to PHP as well? Try echo... – kaiser Oct 15 '13 at 20:08
  • Thanks @kaiser, I used 'action="<?php echo esc_url( wp_login_url() ); ?>"' like suggested below and it does exactly what I need it to. – Designer 17 Oct 15 '13 at 20:50

get_option() returns a string, it doesn’t print anything. You have to use echo or print.

But you should use home_url() instead, because this takes care of the proper scheme (http or https):

echo esc_url( home_url() );

Or, in case of the log in URL:

echo esc_url( wp_login_url() );
  • So, you're saying to do something like... action="<?php echo esc_url( home_url() '/wp-login.php' ); ?> – Designer 17 Oct 15 '13 at 18:42
  • @Designer17 See my update, I missed the log in part. – fuxia Oct 15 '13 at 18:45
  • ah, nvm just figured it out. ;) action="<?php echo esc_url( home_url() ); ?>/wp-login.php" ?> Thanks for the SUPER-FAST help... I'll be sure to come here when I REALY get stuck. – Designer 17 Oct 15 '13 at 18:47
  • @Designer17 No, wp-login.php is not always the URL to log in. That’s just the default, it can be customized. – fuxia Oct 15 '13 at 18:52
  • As Toscho edited his answer: there's a wp_login_url() for that. – Chip Bennett Oct 15 '13 at 18:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.