在我的标题中,我有以下代码:
<?php
global $post;
$pgid = $post->ID;
if (is_user_logged_in() || is_page(344)) { //page 344 is the Login Page
} else {
$url = admin_url();
header("Location: http://cherry.virtek-innovations.com/login-screen");
die();
} ?>这段代码应该将未登录的用户发送到登录页面,但是我得到了以下错误:
Warning: Cannot modify header information - headers already sent by (output
started at /home1/virtek/public_html/cherry/wp-content/themes/twentytwelve/
resumen.php:2) in /home1/virtek/public_html/cherry/wp-content/themes/
twentytwelve/header.php on line 10这是我在resumen.php文件中的代码
<?php
get_header();
/*
Template Name: Resumen
*/
?>我不知道它为什么不能工作,我正在使用用户Meta插件,你们中有人在我的代码中发现了什么错误吗?或者知道任何其他的方法,以拥有一个自定义登录页面,除非您登录,否则不会让您进入?
发布于 2014-07-25 22:04:42
您可以尝试使用wp_redirect()函数来进行重定向吗?例如,将其放在主题的functions.php文件中:
function redirect_logged_out_users() {
if ( ! is_user_logged_in() ) {
wp_redirect( home_url() . '/login-screen/', 301 );
exit();
}
}
add_action( 'template_redirect', 'redirect_logged_out_users' );这在运行template_redirect钩子时执行。这是在将任何内容发送到浏览器之前,这样您就不会得到此方法的“已发送的标题”问题。
参考文献: redirect
https://stackoverflow.com/questions/24960410
复制相似问题