Include Php on certain pages only

Community Forums Forums General Discussion Include Php on certain pages only

This topic is: not resolved

This topic contains 5 replies, has 2 voices, and was last updated by  David Chu 2 years, 8 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #26876



    I would like to know how to include a .php file on the homepage at the beginning of the content area. How is this done? I know Currently, I am using a non efficient method to include my php files (Homepage widget area php plugin). I would like to just include them through the functions.php file. Can anyone help?  The name of the file I would like to include is “ft-sale.php”.

    Also, should I make a seperate .php file for my custom header? If so, how is this done?

    Here are the contents of my functions.php file. If I am doing anything wrong can someone please give me advice?


    Here is the url of my site:


    // Start the engine

    require_once( get_template_directory() . ‘/lib/init.php’ );

    // Child theme (do not remove)

    define( ‘CHILD_THEME_NAME’, ‘Genesis Sample Theme’ );
    define( ‘CHILD_THEME_URL’, ‘’ );

    // Add Viewport meta tag for mobile browsers
    add_action( ‘genesis_meta’, ‘sample_viewport_meta_tag’ );
    function sample_viewport_meta_tag() {
    echo ‘<meta name=”viewport” content=”width=device-width, initial-scale=1.0″/>';


    // Add support for custom background
    add_theme_support( ‘custom-background’ );

    // Add support for custom header
    add_theme_support( ‘genesis-custom-header’, array(
    ‘width’ => 1152,
    ‘height’ => 120
    ) );

    // Add support for 3-column footer widgets
    add_theme_support( ‘genesis-footer-widgets’, 3 );

    /** Register widget areas */
    genesis_register_sidebar( array(
    ‘id’ => ‘home-featured’,
    ‘name’ => __( ‘Home Featured’, ‘sample’ ),
    ‘description’ =>
    __( ‘This is the home featured section.’, ‘sample’ ),
    ) );

    // remove old header, replace
    remove_action(‘genesis_header’, ‘genesis_do_header’);
    remove_action(‘genesis_header’, ‘genesis_header_markup_open’, 5);
    remove_action(‘genesis_header’, ‘genesis_header_markup_close’, 15);
    function custom_header() {

    add_filter(‘genesis_footer_creds_text’, ‘custom_footer_creds_text’);
    function custom_footer_creds_text($creds) {
    $creds = ‘[footer_copyright] ‘ .  get_bloginfo(‘name’) . ‘ ‘;
    return  $creds;


    <div id=”header”>

    <div id=”header-left”>
    <a href=””><img src=”/wp-content/themes/FiretrucksUnlimited/images/used-fire-trucks-for-sale-logo.png”></a>

    <div id=”header-right”>
    <div id=”socialicons”> <a href=”” target=”_blank”><img src=”/wp-content/themes/FiretrucksUnlimited/images/facebook.png” alt=”Our Facebook Page” /></a>
    <a href=”!/FiretrucksUnltd” target=”_blank”><img src=”/wp-content/themes/FiretrucksUnlimited/images/twitter.png” alt=”Folow Us on Twitter” /></a>
    <a href=”″><img src=”/wp-content/themes/FiretrucksUnlimited/images/googleplus.png” alt=”Join Us on Google+” /></a>
    <a href=”” target=”_blank”><img src=”/wp-content/themes/FiretrucksUnlimited/images/linkedin.png” alt=”Connect With Us On LinkedIn” /></a>
    <a href=”” target=”_blank”><img src=”/wp-content/themes/FiretrucksUnlimited/images/youtube.png” alt=”Subscribe to Our Youtube Channel” /></a>
    <a href=”” target=”_blank”><img src=”/wp-content/themes/FiretrucksUnlimited/images/rss2.png” alt=”Subscribe to Our Feed” /></a>

    <div style=”padding: 10px 0;”>
    <span class=”phone”>1-866-876-0979 | <?php if (function_exists(‘iphorm_popup’)) echo iphorm_popup(1, ‘Send a Message’); ?></span>

    <div class=”sharingbox”>
    <div class=”socialonethird”>
    <div class=”fb-like” data-send=”false” data-layout=”button_count” data-width=”450″ data-show-faces=”false” data-colorscheme=”light” data-action=”like”></div>

    <div class=”socialonethird”>
    <a href=”” class=”twitter-share-button” data-related=”jasoncosta” data-lang=”en” data-size=”medium” data-count=”” />Tweet</a>

    <div class=”socialonethird”>
    <div class=”g-plus” data-action=”share” data-annotation=”bubble”></div>



    <div class=”clear”></div>


    <?php }

    add_action(‘genesis_header’, ‘custom_header’);

    add_filter( ‘genesis_breadcrumb_args’, ‘child_breadcrumb_args’ );

    /** Amend Genesis breadcrumb options. **/

    function child_breadcrumb_args( $args ) {

    $args[‘home’] = ‘Home';
    $args[‘sep’] = ‘ / ‘;
    $args[‘list_sep’] = ‘, ‘; // Genesis 1.5 and later
    $args[‘prefix’] = ‘<div class=”breadcrumb”>';
    $args[‘suffix’] = ‘</div>';
    $args[‘heirarchial_attachments’] = true; // Genesis 1.5 and later
    $args[‘heirarchial_categories’] = true; // Genesis 1.5 and later
    $args[‘display’] = true;
    $args[‘labels’][‘prefix’] = ”;
    $args[‘labels’][‘author’] = ‘Archives for ‘;
    $args[‘labels’][‘category’] = ‘Archives for ‘; // Genesis 1.6 and later
    $args[‘labels’][‘tag’] = ‘Archives for ‘;
    $args[‘labels’][‘date’] = ‘Archives for ‘;
    $args[‘labels’][‘search’] = ‘Search for ‘;
    $args[‘labels’][‘tax’] = ‘Archives for ‘;
    $args[‘labels’][‘post_type’] = ‘Archives for ‘;
    $args[‘labels’][‘404′] = ‘Not found: ‘; // Genesis 1.5 and later

    return $args;




    David Chu

    I see you’re going old-school PHP using lots of includes. :-) Here’s an example of a typical include if the file is in the same folder as your child theme:

    require_once( CHILD_DIR . '/custom_functions.php' );

    Unless you have a huge amount of PHP code, I would just use a function along with a Genesis hook to get your goodies into the template. But here’s an example of how you could conditionally pull in the above code.

    add_action( 'genesis_before_post_content', 'my_lovely_function' );
    function my_lovely_function () {
    if ( is_page(42) ) {
    require_once( CHILD_DIR . '/custom_functions.php' );

    To get a list of the hooks (genesis_before_post_content is the hook I’m using here), check out the Visual Hook Guide.


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers



    So you’re saying I should just make templates for pages and use the require_once to bring in the php files. Thanks for your help!



    David Chu

    Not exactly. You can do themes any way you’d like. I’m just giving examples of how I might do something in the Genesis way. What you’re describing is more like the generic WordPress theme method: make a template for each page type, and include PHP into it here and there. Very much traditional PHP. And there’s no way you’d know otherwise, coming in brand new to Genesis, so that’s why I’m giving some examples like that. At first it’s confusing, but once you get used to those hooks, the massive power of Genesis emerges, and anything becomes possible!

    I was once asked to make modifications to a custom Genesis theme. The site was live, and the theme worked fine, but it was very clear that the coder knew nothing about Genesis, because they didn’t use any Genesis hooks or functions, instead they had dozens of template files, and zillions of includes – very much like a generic WordPress theme. It all worked, but it was extremely hard to find anything, and it utilized zero of the power of Genesis. I ended up spending as much time hunting for stuff as I did coding. :-)

    My child themes usually have just 2 files: functions.php and style.css. That’s it! Even if I have a fully tricked-out homepage, I can usually get everything I want using hooks, filters, sidebars, and CSS. The functions file may have a few includes, and all the rest of the PHP code consists of functions, which are called conditionally and via hooks. You could say that I’m an extreme minimalist – others might always make a home.php, and so on, and there’s nothing wrong with that.

    Another way to think of it is that Genesis framework has so many layouts built-in, that you just call them at will, and alter them on-the-fly if you want.

    That’s probably more bloviation than you asked for, but I’m in a chatty mood, and I hope it helps a little!


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers



    Thank you, very informative!


    David Chu

    Glad that was helpful!

    By the way, there is one time that I definitely add some extra files via includes.  That’s when someone has me working on one of the non-custom Genesis child themes, like the ones you see for sale here.  In that case, I will have at least a custom functions file separate from the main one, and also a custom CSS file.  (and possibly others if there’s a lot of custom programming)

    This is a safety and convenience measure.  Let’s say someone hires me to modify Minimal, Metro, or one of the other themes here.  Then a theme update (or bugfix) comes out from Studiopress.  The person sees that, and updates without backing up.  Doh!!  All of a sudden, oh oh, their site looks funny, or has lost some stuff!

    Then I (or they) can restore my changes to their site with two 1-line code changes!   Whereas if I had stuck all my changes in their stock functions.php and style.css, it would be a pretty big deal to thread these changes back in.  Stuff that innocent site owners don’t know about.  :-)   Yes, they’re warned to back up, but they just ignore that, or get nervous thinking about it and avoid it for that reason.

    I think I might adapt my bloviations here for a blog post.  Thanks for the idea!


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.