Hello my friends, after a long time sat down to write a post for an wordpress issue. So, Lets go to the topics we learn today.
Some time after completing our wordpress theme development we faced a fatal error on serverside error_log like
[01-Jun-2014 11:25:15] PHP Fatal error: Call to undefined function get_header() in /home/accountname/public_html/rootwp/wp-content/themes/themename/index.php on line 1.
Where main index.php contains the following codes at the top of the php document.
<?php get_header(); ?>
Now the fact is its a bothering error after completing a theme but there is no way found for which you got this error. Basically It’s a php fatal error issue for some reasons of functions conflict. But following this error I found a way to handle this error by php where it works by checking the function_exist() on index.php.
To do that we follow three simple steps:
- Checking get_header function exist or not.
- If exist then add get_header();
- Otherwise redirect browser to default host address.
So lets checkout my index.php now
<?php if (function_exists('get_header')) { get_header(); }else { /* Redirect our browser */ header("Location: http://" . $_SERVER['HTTP_HOST'] . ""); /* Make sure that code below does not get executed when we redirect. */ exit; }; ?>
Hurrah ! We have lost the error from server error_log now by simply edit these lines to index.php
By this way I didn’t get any more fatal error of undefined get_header() on my server error_log. Hope that would be helpful to you too.
Isn’t it simple :p Have a great time with wordpress.