Support » Developing with WordPress » “get_header” function isn’t working for certain pages

  • Anonymous User 17951214

    (@anonymized-17951214)


    Hello fellow WordPress users!
    I am working on a WordPress website and have come across a critical error:
    I have created a header.php file and tried using the get_header() function to import the header into all of my pages. In my index.php page it works perfectly, but in all of my other pages, I get an error message saying “Fatal error: Uncaught Error: Call to undefined function get_header()”. For experimental purposes, the code in my index.php page is the same as in all of my other .php pages. What am I doing wrong? Here Is the code for one of my pages “feedback.php”:

    <!DOCTYPE html>
    <!DOCTYPE html>
    <html>
    <head>
    
    <!-- Import Header from header.php -->
    <?php get_header() ?>
        
    <!-- Basic Responsivness -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width", initial-scale=1.0>
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title> Home </title>
    <link href="https://fonts.googleapis.com/css2?family=Notable&display=swap" rel="stylesheet">
    
    <style type="text/css">
    
    h2 {
    font-family: 'Notable', sans-serif;
    }
    
    </style>
    
    </head>
    <body>
    <h2> Hello World </h2>
    </body>
    </html>
Viewing 2 replies - 1 through 2 (of 2 total)
  • How does this feedback.php file get loaded? If you call it directly in the URL, WordPress is not loaded, so your function is undefined.
    Please read about the Template Hierarchy which is how theme templates are called. While there, you can read more of the Theme Developer Handbook.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @wirewordpress Don’t create duplicate topics. I have archived your new topic.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘“get_header” function isn’t working for certain pages’ is closed to new replies.