首页 文章

functions.php导致Wordpress中的 Headers 错误

提问于
浏览
-1

我的wordpress主题有问题,functions.php文件输出错误的 Headers 错误:

警告:无法修改 Headers 信息 - 已在/ home / slavisap / public_html /中发送的 Headers (输出从/ home / slavisap / public_html / femarkets / wordpress / wp-content / themes / Flex E / functions.php:67开始)第934行的femarkets / wordpress / wp-includes / pluggable.php

当我尝试访问某个页面或从管理员创建另一个页面时,它会随机发生 .

这是我的functions.php:

<?php
if (function_exists('register_nav_menus')) {
    register_nav_menus(
            array(
                'primary' => 'Primary Header Nav',
                'footer_menu' => 'Footer Menu',
                'exploring' => 'Exploring Page Menu',
                'using' => 'Using Page Menu',
                'downloading' => 'Downloading Page Menu'
            )
    );
}
function get_breadcrumbs() {
    global $wp_query;

    if (!is_home()) {

        // Start the UL
        echo '<ul class="breadcrumbs">';
        // Add the Home link
        echo '<li><a href="' . get_settings('home') . '">' . get_bloginfo('name') . '</a></li>';

        if (is_category()) {
            $catTitle = single_cat_title("", false);
            $cat = get_cat_ID($catTitle);
            echo "<li> &#47; " . get_category_parents($cat, TRUE, " &#47; ") . "</li>";
        } elseif (is_archive() && !is_category()) {
            echo "<li> &#47; Archives</li>";
        } elseif (is_search()) {

            echo "<li> &#47; Search Results</li>";
        } elseif (is_404()) {
            echo "<li> &#47; 404 Not Found</li>";
        } elseif (is_single()) {
            $category = get_the_category();
            $category_id = get_cat_ID($category[0]->cat_name);

            echo '<li> &#47; ' . get_category_parents($category_id, TRUE, " &#47; ");
            echo the_title('', '', FALSE) . "</li>";
        } elseif (is_page()) {
            $post = $wp_query->get_queried_object();

            if ($post->post_parent == 0) {

                echo "<li> &#47; " . the_title('', '', FALSE) . "</li>";
            } else {
                $title = the_title('', '', FALSE);
                $ancestors = array_reverse(get_post_ancestors($post->ID));
                array_push($ancestors, $post->ID);

                foreach ($ancestors as $ancestor) {
                    if ($ancestor != end($ancestors)) {
                        echo '<li> &raquo; <a href="' . get_permalink($ancestor) . '">' . strip_tags(apply_filters('single_post_title', get_the_title($ancestor))) . '</a></li>';
                    } else {
                        echo '<li> &raquo; ' . strip_tags(apply_filters('single_post_title', get_the_title($ancestor))) . '</li>';
                    }
                }
            }
        }

        // End the UL
        echo "</ul>";
    }
}
?>

我的网站网址:http://slavisaperisic.com/femarkets/wordpress/

你知道我做错了吗?

1 回答

  • 7

    由于你发布的functions.php文件中没有第67行(至少是我复制/粘贴到我的编辑器中的版本),我猜你在函数的开头和/或结尾都有一些额外的空格 . .php文件(在打开 <?php 之前或在关闭 ?> 标记之后) .

    <?php ?> 标记之外的PHP文件中的任何字符都被视为标准输出,并立即写入STDOUT(或Web服务器输出流),在Web服务器方案中,这将导致 Headers 被发送,因为您输出的是回应的主体 .

    确保开头 < 是文件中的第一个字符,而结束 > 是文件中的最后一个字符 .

    如果文件中的所有数据都是PHP代码,你实际上不需要包含一个结束 ?> 标记,省略它将有助于避免这样的问题......

相关问题