• Resolved darrenalawi

    (@darrenalawi)


    How can I call a function that is “undefined”?

    I have created a custom error message for when users do not enter required info into the comment form (try it here if you want, just hit enter with the field empty: http://www.darrenalawi.com/blog/index.php/google-vs-apple/)

    The message appears as part of a small hack, and is just XHTML from:

    http://www.darrenalawi.com/wordpress/wp-content/themes/darrenalawi/error.php

    What I want to do is replace the XHTML for the header, sidebar and footer with call functions like:

    <?php get_header(); ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    But whenever I swap out the XHTML in the error.php file for any of these calls, and load the page (by submtting incorrect form) I get:

    Fatal error: Call to undefined function: get_header() in e:\domains\d\darrenalawi.com\user\htdocs\wordpress\wp-content\themes\darrenalawi\error.php on line 1

    etc…

    Can anyone enlighten me?

Viewing 4 replies - 1 through 4 (of 4 total)
  • In general you cannot just add a new template to your theme which falls outside the template hierarchy and expect WordPress to know about it (or for it to know about WordPress). To make such a PHP document WP-aware, you need to first include the wp-blog-header.php file, which is discussed here:

    http://codex.wordpress.org/Creating_a_Static_Front_Page#Integrating_WordPress

    Thread Starter darrenalawi

    (@darrenalawi)

    Hi Kafkaesqui,

    Thanks for the quick response, great advice. I added the code to the top of the file and now get this message:

    Warning: main(./wordpress/wp-blog-header.php) [function.main]: failed to open stream: No such file or directory in e:\domains\d\darrenalawi.com\user\htdocs\wordpress\wp-content\themes\darrenalawi\error.php on line 3

    Fatal error: main() [function.require]: Failed opening required ‘./wordpress/wp-blog-header.php’ (include_path=’.;c:\php4\pear’) in e:\domains\d\darrenalawi.com\user\htdocs\wordpress\wp-content\themes\darrenalawi\error.php on line 3

    I assume this is because the php file I inserted this code into isn’t in the root of the domain?

    Can you offer any more of your expertise?

    The require line would need to point to the location of wp-blog-header.php in your WordPress installation. The path provided on the Codex page is just an example.

    You can try using the full path the error noted:

    require('e:\domains\d\darrenalawi.com\user\htdocs\wordpress\wp-blog-header.php');

    Thread Starter darrenalawi

    (@darrenalawi)

    Hi Kafkaesqui,

    Thats great and it worked as well!! Thanks for your help.

    Darren.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Calling functions’ is closed to new replies.