0

I'm building theme and using this link in navigation bar to about.php page.

<li><a href="<?php echo get_template_directory_uri(); ?>/about.php">אודות</a></li>

Now I can't understand why but when I enter about.php I get the following error:

Fatal error: Uncaught Error: Call to undefined function get_header() in D:\XAMPP\htdocs\wordpress\wp-content\themes\photography\about.php:2 Stack trace: #0 {main} thrown in D:\XAMPP\htdocs\wordpress\wp-content\themes\photography\about.php on line 2

About.php page

<?php get_header(); ?>

<?php get_footer(); ?>

I'm not sure if I need to define something in my functions.php file.

How can I load properly get_header(); function in about.php?

1

Look into the theme template hierarchy. There is no "about.php" file and you should not link to any of the theme (PHP) files directly. Instead, you would create a theme file such as "page-about.php" and create its content in wp-admin as a Page with the slug "about," and WordPress will process that Editor content within the PHP file to create the final visible page. If you have pretty permalinks enabled you will want to link to "/about/" instead of the theme file, but because you have named the PHP file "page-about," WP will apply it to a Page with the slug "about."

| improve this answer | |
  • Can you redirect me so I can read more about the template hierarchy? I understand, I added through wordpress dashboard new page but It doesn't show up in my theme folder. also shows me the same page as index.php – Yotam Dahan Jul 10 at 13:57
  • @YotamDahan The Template Hierarchy page is a good starting point. – Pat J Jul 10 at 14:04
  • @PatJ Changed my link to this <?php echo get_template_directory_uri(); ?>/index.php?page_id=15 and still having the same error, my page name is page-about.php now – Yotam Dahan Jul 10 at 14:17
  • 2
    You should not be linking to PHP files inside your theme, ever. If you want to output a link to a page with PHP you should use get_the_permalink( $id ), where $id is the page ID. In your case though you should be using WordPress navigation menus to output these links, rather than hardcoding them like this. – Jacob Peattie Jul 10 at 14:38
  • Right, with standard permalinks you would just link to "example.com/?page_id=15" or whatever URL it shows as the Permalink in the Editor. – WebElaine Jul 10 at 19:13
-2

get_header() is part of wordpress core.

Seems your wordpress files damaged or installed incorrect. Try to reinstall it. Probably you should move D:\XAMPP\htdocs\wordpress into D:\XAMPP\htdocs\

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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