Title: Inline PHP vs functions.php
Last modified: August 19, 2016

---

# Inline PHP vs functions.php

 *  Resolved [lemaxim](https://wordpress.org/support/users/lemaxim/)
 * (@lemaxim)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/inline-php-vs-functionsphp/)
 * 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)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 4 months ago](https://wordpress.org/support/topic/inline-php-vs-functionsphp/#post-693745)
 * > _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.

 * 1 reply
 * 2 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [18 years, 4 months ago](https://wordpress.org/support/topic/inline-php-vs-functionsphp/#post-693745)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
