I have a site with a listings page (/) and all I'm trying to do is redirect a user who is not logged in to my login page (/) before they can view an individual listing. If they are logged in then they can go straight to the individual listing.
I'd like to do this without having to use a plugin as this seems like it should be a relatively easy thing to do via php.
Thanks!
I have a site with a listings page (https://gymkoi/class-listings/) and all I'm trying to do is redirect a user who is not logged in to my login page (https://gymkoi/login/) before they can view an individual listing. If they are logged in then they can go straight to the individual listing.
I'd like to do this without having to use a plugin as this seems like it should be a relatively easy thing to do via php.
Thanks!
Share Improve this question asked May 21, 2020 at 17:34 Jon TimmsJon Timms 132 bronze badges 2- Quick question, after they login are they then directed to a page of listings or a specific listing? – Tony Djukic Commented May 21, 2020 at 20:12
- eventually i'd like them to go to the listing they clicked on – Jon Timms Commented May 21, 2020 at 21:41
1 Answer
Reset to default 2You could set up a child theme, and in the single-listing.php
template, add conditions around the current code.
<?php
// If the user is not logged in, redirect
if ( false == is_user_logged_in() ) {
wp_redirect( wp_login_url() );
exit;
}
// Else the user is logged in; show the listing
else {
// Paste the regular template code here
}
?>
Everything else will remain public, while just the individual listings will force the user to be logged in before they can view the content. (This will also prevent search engines from seeing the content, so bear that in mind.)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742412303a4439054.html
评论列表(0条)