rlthorman
Member
Posted 1 year 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?
rlthorman
Member
Posted 1 year 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>
Frank P. Walentynowicz
Member
Posted 1 year 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 } ?>
rlthorman
Member
Posted 1 year 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!