WordPress无法修改标题

时间:2016-08-18 19:50:01

标签: php wordpress

我有一个安装了WordPress 4.6的网站,尝试移动菜单项点击打开的第一个子页面。试图做那个wp_redirect,但它不起作用。

Warning: Cannot modify header information - headers already sent by (output started at /home/content/65/9303265/html/wp-content/themes/ThemeName/page-gotochild.php:8) in /home/content/65/9303265/html/wp-includes/pluggable.php on line 1174

我试图删除空格和行并替换wp-admin和wp-includes但它不起作用。

我用来重定向的代码:

<?php
/*
    Template Name: Go to first child
*/
$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
if ($pagekids) {
    $firstchild = $pagekids[0];
    wp_redirect(get_permalink($firstchild->ID));
}?>

2 个答案:

答案 0 :(得分:1)

<?php
/*
    Template Name: Go to first child
*/
$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
if ($pagekids) {
   $firstchild = $pagekids[0];
   wp_redirect(get_permalink($firstchild->ID));
   exit;
}?>

执行重定向时始终尝试调用exit。有关详细信息,请参阅代码中的此链接。

"Note: wp_redirect() does not exit automatically, and should almost always be followed by a call to exit;:"

答案 1 :(得分:0)

我找到了我的答案,在根文件夹中我有相同文件名的文件,比如我要重定向的链接。