首页 > 解决方案 > how to solve header location warning wordpress

问题描述

Hi I want to create a simple login code to redirect each user to his own profile page.

I'm using a page "CleanPage" as a template for my php code.

I tried header Location and wp_redirect but both shows this error:

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/general-template.php:1076) in /var/www/html/wp-content/themes/sydney/CleanPage.php on line 43

I wanted simple redirection like this:

header("Location: auth_customer.php?id=$userid");

Any help please?

标签: phpwordpressheader

解决方案


虽然我已经在上面的评论部分发布了链接。我相信这绝对可以解决您的问题

<?php
add_action( 'send_headers', 'add_header_xua' );
function add_header_xua() {
    // your login logic or whatever should go here
    // ....
    header("Location: auth_customer.php?id=$userid");
}

推荐阅读