title: Why won't wp_list_pages work in functions.php?
body: <p>I'm using the following code to add a submenu that only displays the current top level parent and any children pages if within their parent. It works when used directly in sidebar.php but when I wrap it in a function and place it in functions.php, it only shows all of my top level menu items and not the active parent. How can I get it to work?</p>
  
  <p><strong>Works in the sidebar:</strong></p>
  
  <pre><code>&lt;?php
  $child_of_value = ( $post-&gt;post_parent ? $post-&gt;post_parent : $post-&gt;ID );
      $depth_value = ( $post-&gt;post_parent ? 2 : 1 );
          $wp_list_pages_args = array( 
              'child_of' =&gt; $child_of_value,
              'depth' =&gt; $depth_value,
              'title_li' =&gt; '&lt;a href="'.get_permalink($post-&gt;post_parent).'"&gt;'.get_the_title($post-&gt;post_parent).'&lt;/a&gt;'
          );
      wp_list_pages( $wp_list_pages_args );
  ?&gt;
  </code></pre>
  
  <p><strong>Doesn't work in functions.php</strong></p>
  
  <pre><code>function page_submenu() {   
      $child_of_value = ( $post-&gt;post_parent ? $post-&gt;post_parent : $post-&gt;ID );
      $depth_value = ( $post-&gt;post_parent ? 2 : 1 );
          $wp_list_pages_args = array( 
              'child_of' =&gt; $child_of_value,
              'depth' =&gt; $depth_value,
              'title_li' =&gt; '&lt;a href="'.get_permalink($post-&gt;post_parent).'"&gt;'.get_the_title($post-&gt;post_parent).'&lt;/a&gt;'
          );
      wp_list_pages( $wp_list_pages_args );
  }
  </code></pre>