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() {
var_dump($post);
$page = $post;
$parents = array();
while ($page->post_parent){
array_push($parents, $page);
$page = $page->post_parent;
}
if (sizeof($parents) > 0) {
array_reverse($parents);
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?
Call in
global $post;
at the top of the function.