WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Execute PHP wp_login_url on single post? (4 posts)

  1. rlthorman
    Member
    Posted 3 years ago #

    I can't get this PHP to execute in a single post. It will execute just fine embedded on a post on the main page, but will not execute when embedded on a post and you click on that post, and see it in single post view.

    " title="Login">sign in

    (I'm using plugin PHP Execution to get the PHP to execute in the HTML)

    The purpose is that users will need to login before seeing the rest of the post.

    Any ideas?

  2. rlthorman
    Member
    Posted 3 years ago #

    Sorry, forgot the backticks. Here's the code I'm trying to execute-

    <a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">sign in</a>

  3. Frank P. Walentynowicz
    Member
    Posted 3 years ago #

    That should work unless you use one of redirection plugins (eg. Peter's Login Redirect). I understand that you want to use it this way:

    <?php if ( is_user_logged_in() ) { ?>
    ... protected content ...
    <?php } else { ?>
    You must <a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">sign in</a> to see this post.<?php } ?>
  4. rlthorman
    Member
    Posted 3 years ago #

    I figured out the problem - I was trying to execute it after a More tag, which I have since learned is ignored in single.php.

    I used shortcodes instead to make things work.

    Thanks for your help!

Topic Closed

This topic has been closed to new replies.

About this Topic