wordpress网站页面登录才能访问

        代码需要考虑两个东西,1、判断登录,2、跳转登录并登录跳转本页面(获取本页面链接)。这两个东西我都整合到我的一行代码了,代码如下:

<?php if(!is_user_logged_in()){header('Location: https://xiaozu.uesdto.com/wp-login.php?redirect_to='.esc_url( home_url( $_SERVER['REQUEST_URI'] )));exit;}?>

        也是够简单的,但也是经常遇到记录下,比如我新建了个页面模板,加入其中,新建页面时选择它,页面就只有登录才能看到了,代码如下:

<?php
/**
 * Template Name: 全宽登录可见模板
 *
 * @link https://www.kekc.cn/wp-content/uploads/2022/04/xiaozu.uesdto.com/wp-login.php?redirect_to='.esc_url( home_url( $_SERVER['REQUEST_URI'] )));exit;}?>
<?php beehive()->layout->set( 'full' ); ?>
<?php get_header(); ?>
<?php get_template_part( 'template-parts/before-template' ); ?>
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', 'page' );
/** If comments are open or we have at least one comment, load up the comment template. */
if ( comments_open() || get_comments_number() ) :
comments_template();
  endif;
endwhile; // End of the loop.
?>
<?php wp_reset_postdata(); ?>
  
<?php get_template_part( 'template-parts/after-template' ); ?>
<?php
get_footer();
© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容