2

I downloaded a WordPress theme recently, and I tried to run it, but it gives me a fatal error showing a call to undefined fatal error(). Why is this error generated?

I am new to WordPress theme development. Here are my index.php and header.php scripts. How can I get rid of this error?

File index.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>

File 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; ?>">
  • 2
    This is core function and can never be undefined. Did you try re installing WordPress ? – Sumit May 13 '16 at 17:56
  • You shouldn't indent your opening PHP tag like that, it should always be the very first thing in the file. in this case it only works because it's a template file – Tom J Nowell May 14 '16 at 13:19
  • Also, this type of error usually indicates that the file is being loaded directly in the browser, usually as a form handler or an AJAX endpoint. This is bad and should never be done and is a security risk – Tom J Nowell May 14 '16 at 13:20
2

Something went wrong with your installation. As commented by @Sumit get_header() is a core function and cannot be undefined.

To troubleshoot: Reinstall WordPress and enable WP_DEBUG in wp_config.php:

define( 'WP_DEBUG', true );

If it is on a live site you might want to use this instead:

define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

This will list your errors in an error log in the wp-content folder.

Your site should display normally using a default theme with no errors.

Activate your theme and check for errors.

Not the answer you're looking for? Browse other questions tagged or ask your own question.