Title: php require_once() function
Last modified: August 19, 2016

---

# php require_once() function

 *  [imanerd](https://wordpress.org/support/users/imanerd/)
 * (@imanerd)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/php-require_once-function/)
 * I’m trying to figure out how to eliminate redundant code by using includes. For
   example, a theme that I’m working on has the following meta info for each post:
 * `<p class="postmeta"><?php the_time('M j, Y'); ?> | <?php the_author(); ?> | 
   <?php the_category(', ') ?> | <a href="<?php comments_link(); ?>" class="comments"
   >Comments (<?php comments_number('0','1','%'); ?>)</a></p>`
 * This code is located in several theme files so if I want to rearrange items (
   e.g., place the author before the date), I would have to edit the same code in
   multiple places. The ability to use includes would make updates such as this 
   much easier. Please help…

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/php-require_once-function/#post-1026263)
 * You could try creating a function that echoes out your code and placing it in
   functions.php within your theme. Then replace the code in the individual template
   files with a call to your new function. You don’t have to include any call to
   functions.php first. WordPress does that by default.
 *  [t31os](https://wordpress.org/support/users/t31os/)
 * (@t31os)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/php-require_once-function/#post-1026275)
 * You could wrap that inside a function and even add the ability to switch the 
   display order with some minor arguments…
 * Simply put a function just runs a set of code….
 *     ```
       <?php function my_example() {
       echo 'this is my example';
       }?>
       ```
   
 * then the call..
    `<?php my_example(); ?>`
 * Would output…
 * > this is my example
 * Esmi it’s not a simple matter of echo’ing the content unfortunately because not
   all WP functions operate on that basis.. some return, some echo…etc…
 * I can give some examples if you want to put it into a function…..
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/php-require_once-function/#post-1026276)
 * True – though I’m pretty sure most of those particular native WP functions actually
   echo (e.g. `the_category` or `the_author`). So, if you’re not used to writing
   theme functions, it may be a lot easier to echo them out than try to return them.
   Otherwise you end up with the WP function outputs appearing **before** your customised
   markup – which then means finding similar functions that ‘return’ instead of ‘
   echo’. All of which can be a bit overwhelming if it’s your first function. 🙂
 *  [t31os](https://wordpress.org/support/users/t31os/)
 * (@t31os)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/php-require_once-function/#post-1026277)
 * I usually just print, echo each one and see what i get, then dig around in the
   files if i’m still confused….
 * Not that i’m sure it makes a difference, i end up confused half the time anyway….:-
   s …
 *  Thread Starter [imanerd](https://wordpress.org/support/users/imanerd/)
 * (@imanerd)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/php-require_once-function/#post-1026299)
 * Thanks for the info. Prior to posting this topic, I tried creating a function
   in functions.php with a single statement `echo "test";` and it totally broke 
   wordpress when I saved. I couldn’t even get in the admin panel (good thing I 
   was working on a development server).
 * I should also add that I’m very comfortable with php/mysql but relatively new
   to wordpress.
 *  [t31os](https://wordpress.org/support/users/t31os/)
 * (@t31os)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/php-require_once-function/#post-1026302)
 * Theme functions aren’t called into the admin – unless told to do so, so i can’t
   see how a basic function caused a problem like that…
 * It was proberly a minor typo or something silly…
 * I usually test my fuctions directly in the template then move it to the functions
   file once it works.
 * It’s the same proceedure you’d use for a normal PHP function….
 *  Thread Starter [imanerd](https://wordpress.org/support/users/imanerd/)
 * (@imanerd)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/php-require_once-function/#post-1026346)
 * It works now…I had to disable a couple of my security plugins.
 * Thanks for the help!
 *  [chriseriksson](https://wordpress.org/support/users/chriseriksson/)
 * (@chriseriksson)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/php-require_once-function/#post-1026512)
 * esmi,
    im require_once(wp_config.php) and like you said it echoes out stuff automatically.
   Is there any way to get rid of this without locating the source of the echo. 
   Like deleting straight after the call whatever it is echoing? I don’t know php
   that well…
 * Thanks,
    Chris

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘php require_once() function’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)
 * [require_once](https://wordpress.org/support/topic-tag/require_once/)

 * 8 replies
 * 4 participants
 * Last reply from: [chriseriksson](https://wordpress.org/support/users/chriseriksson/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/php-require_once-function/#post-1026512)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
