• Resolved lemaxim

    (@lemaxim)


    When I put
    <?php echo get_the_title($post->post_parent) ?>
    into my theme template the output is correct.

    However, if I try to put it into a function and then call it from functions.php it does not work. Are there some sort of global variables that I should be calling?

    I’m trying to use this with conditional parameters in the functions.php file because the template itself would get quite bloated if I had it inline.

    Thanks in advance for any help!

Viewing 1 replies (of 1 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    When I put
    <?php echo get_the_title($post->post_parent) ?>
    into my theme template the output is correct.

    However, if I try to put it into a function and then call it from functions.php it does not work. Are there some sort of global variables that I should be calling?

    Should be obvious, no? You are directly using the global variable $post (you’re trying to access the $post->post_parent variable). So you need to put global $post; at the top of your function.

    function whatever()
    {
    global $post;
    echo get_the_title($post->post_parent);
    ...
Viewing 1 replies (of 1 total)
  • The topic ‘Inline PHP vs functions.php’ is closed to new replies.