wordpress网站页面登录才能访问
2023-06-13 09:15:05 时间
代码需要考虑两个东西,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://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage beehive
* @since 1.0.0
*/
/** Do not allow directly accessing this file. */
if ( ! defined( 'ABSPATH' ) ) {
exit( 'Direct script access denied.' ); } ?>
<?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 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();
相关文章
- wordpress免插件设置回复后可见
- WordPress网站Gravatar头像完美替代方案:Cravatar
- WordPress博客网站伪静态设置及固定链接设置教程-解决404问题
- lamp部署-WordPress站点上线
- WordPress等博客使用QQ微信微博第三方授权登陆网站的实现方法
- WordPress网站下雪特效
- 如何安装网站程序,怎么安装wordpress
- WordPress 子比主题保存设置时出现function(){return u(n),r.apply(this,arguments)}该怎么办?[解决办法]
- WordPress 网站自动为文章添加特色图像
- WordPress 网站正文顶端或者末尾插入固定内容的方法
- WordPress 使用 CDN 后获取访客真实 IP
- WordPress IndexNow提交教程,让搜索引擎快速收录
- WordPress 获取 URL 链接路径的几种方法
- 谁不想要一个自己的博客网站呢 - 搭建博客网站wordpress
- WordPress网站首页分类菜单样式美化
- WordPress网站B2主题会员展示模块
- WordPress 网站管家小程序源码
- wordpress新手应该做的
- WordPress 博客网站设置圣诞节雪花效果的实现方法
- 5分钟傻瓜式教程:wordpress搭建个人博客网站
- WordPress 文章超过10万就会负载很高,是不是不适合做大网站?
- WordPress 技巧:无需输入 FTP 信息就能升级 WordPress 及插件
- WordPress 5.7 发布
- 黑客试图在受到攻击的 WordPress 网站创建管理员帐户