WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to use the $post object from functions.php in my theme however if I attempt to var_dump($post) it returns NULL.

Here is my code:

function breadcrumb_navigation() {
    $page = $post;
    $parents = array();
    while ($page->post_parent){
        array_push($parents, $page);
        $page = $page->post_parent;
    if (sizeof($parents) > 0) {
        foreach($parents as $parent) {
            echo '<li><a href="'.get_permalink($parent->ID).'">'.$parent->post_title.'</a><ul class="child">', wp_list_pages(array('child_of' => $post->post_parent,'exclude' => $post->ID)), '</ul></li>';

Can anyone tell why this would be happening?

share|improve this question
up vote 1 down vote accepted

Call in global $post; at the top of the function.

share|improve this answer
That was simple :P – George Reith Apr 13 '12 at 15:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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