WordPress致命错误:在第15行调用index.php中未定义的Get_Header()

时间:2016-05-13 作者:Vinod Dirishala

我最近下载了一个WordPress主题,并尝试运行它,但它给了我一个致命错误,显示了对undefined fatal error()的调用。为什么会产生此错误?

我是WordPress主题开发的新手。这是我的索引。php和标题。php脚本。如何消除此错误?

文件索引。php

<?php
    /**
    * The main template file.
    *
    * This is the most generic template file in a WordPress theme
    * and one of the two required files for a theme (the other being style.css).
    * It is used to display a page when nothing more specific matches a query.
    * E.g., it puts together the home page when no home.php file exists.
    *
    * @link https://codex.wordpress.org/Template_Hierarchy
    *
    * @package Astrid
    */

    get_header(); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

            <?php
                if ( have_posts() ) :

                    if ( is_home() && ! is_front_page() ) : ?>

                    <header>
                        <h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
                    </header>

文件头。php

<?php
    /**
     * The header for our theme.
     *
     * This is the template that displays all of the <head> section and everyth ing up until <div id="content">
     *
     * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
     *
     * @package Astrid
     */

?><!DOCTYPE html>
<html <?php language_attributes(); ?>>

    <head>
        <meta charset="<?php bloginfo( \'charset\' ); ?>">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="profile" href="http://gmpg.org/xfn/11">
        <link rel="pingback" href="<?php bloginfo( \'pingback_url\' ); ?>">

        <?php wp_head(); ?>
    </head>

    <body <?php body_class(); ?>>

        <div class="preloader">
            <div class="preloader-inner">
                <ul><li></li><li></li><li></li><li></li><li></li><li></li></ul>
            </div>
        </div>

        <div id="page" class="site">
            <a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( \'Skip to content\', \'astrid\' ); ?></a>

            <header id="masthead" class="site-header <?php echo astrid_has_header(); ?>" role="banner">
                <div class="container">
                    <div class="site-branding col-md-4 col-sm-6 col-xs-12">
                        <?php astrid_branding(); ?>
                    </div>
                    <div class="btn-menu col-md-8 col-sm-6 col-xs-12"><i class="fa fa-navicon"></i></div>
                    <nav id="mainnav" class="main-navigation col-md-8 col-sm-6 col-xs-12" role="navigation">
                       <?php wp_nav_menu( array( \'theme_location\' => \'primary\', \'menu_id\' => \'primary-menu\' ) ); ?>
                    </nav><!-- #site-navigation -->
                </div>
            </header><!-- #masthead -->

            <?php if ( astrid_has_header() == \'has-header\' ) : ?>
            <div class="header-image">
                <?php astrid_header_text(); ?>
                <img class="large-header" src="<?php header_image(); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" alt="<?php bloginfo(\'name\'); ?>">

                <?php $mobile_default = get_template_directory_uri() . \'/images/header-mobile.jpg\'; ?>

                <?php $mobile = get_theme_mod(\'mobile_header\', $mobile_default); ?>
                <?php if ( $mobile ) : ?>
                <img class="small-header"
                     src="<?php echo esc_url($mobile); ?>"
                     width="                     <?php echo esc_attr( get_custom_header()->width ); ?>"
                     alt="<?php bloginfo(\'name\'); ?>">
                <?php else : ?>
                <img class="small-header" src="<?php header_image(); ?>" width="1024" alt="<?php bloginfo(\'name\'); ?>">
                <?php endif; ?>
            </div>
            <?php elseif ( astrid_has_header() == \'has-shortcode\' ) : ?>
            <div class="shortcode-area">
                <?php $shortcode = get_theme_mod(\'astrid_shortcode\'); ?>
                <?php echo do_shortcode($shortcode); ?>
            </div>
            <?php else : ?>
            <div class="header-clone"></div>
            <?php endif; ?>
            <?php if ( !is_page_template(\'page-templates/page_widgetized.php\') ) : ?>
            <?php $container = \'container\'; ?>
            <?php else : ?>
            <?php $container = \'home-wrapper\'; ?>
            <?php endif; ?>

            <?php do_action(\'astrid_before_content\'); ?>

            <div id="content" class="site-content">
            <div class="<?php echo $container; ?>">

1 个回复
SO网友:mantis

您的安装出现问题。如@Sumit所评论get_header() 是核心函数,不能未定义。

疑难解答:重新安装WordPress并在WP\\U配置中启用WP\\U调试。php:

define( \'WP_DEBUG\', true );
如果它位于实时站点上,您可能希望改用它:

define( \'WP_DEBUG_LOG\', true );
define( \'WP_DEBUG_DISPLAY\', false );
这将在wp content文件夹的错误日志中列出您的错误。

您的站点应该使用默认主题正常显示,没有错误。

激活主题并检查错误。