WordPress.org

Ready to get started?Download WordPress

Forums

Difference between php include and wp get_header etc. ? (6 posts)

  1. richarduk
    Member
    Posted 7 years ago #

    Can anyone tell me if there's a huge amount of difference between using '<?php get_header(); ?>' and a theoretical
    '<?php include("header.inc")?>' ?

    Is it a speed thing?

  2. whooami
    Member
    Posted 7 years ago #

    those are completely different animals.

    <?php get_header(); ?> is calling the function named get_header that is defined elsewhere.

    while, <?php include("header.inc")?> is attempting to include a file named header.inc

    so yes, on the face, theres a huge amount of difference.

    If however, you are are attempting to substitute a file named header.inc for the standard wordpress function, that would work.

    And no there wouldnt be any measurable difference. it would be measured in miliseconds.

  3. richarduk
    Member
    Posted 7 years ago #

    Right, thankyou.

    I should have used get_footer as it would have been easier to explain what I want to do.

    I've have hard-coded the same footer across various categories, archives etc. but was thinking of including a standard email address and some tracking code into the bottom of each of these. (Email address and tracking code could change at any time)

    I know we're only talking about milliseconds, but the milliseconds surely add up, especially if there's a reasonable amount of traffic?

    The function get_footer effectively seems to do the same thing as an include.

    function get_footer() {
    if ( file_exists( TEMPLATEPATH . '/footer.php') )
    load_template( TEMPLATEPATH . '/footer.php');
    else
    load_template( ABSPATH . 'wp-content/themes/default/footer.php');

  4. richarduk
    Member
    Posted 7 years ago #

    Or should I use
    <?php include (TEMPLATEPATH . '/footer.inc'); ?>

  5. moshu
    Member
    Posted 7 years ago #

    get_footer = is a WP specific thing; it is defined in the core files and it works accordingly.

    include (richarduk.php) = is a general PHP thing for including any file

    the TEMPLATEPATH version works only if the non-standard, non-WP template file is located in the theme folder

  6. richarduk
    Member
    Posted 7 years ago #

    Thanks :-)

Topic Closed

This topic has been closed to new replies.

About this Topic