Title: Add php to index.php
Last modified: August 20, 2016

---

# Add php to index.php

 *  Resolved [ehoanshelt](https://wordpress.org/support/users/ehoanshelt/)
 * (@ehoanshelt)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/add-php-to-indexphp/)
 * On the index.php file of my theme, there is a section of html that I would like
   to add some php too. The html looks like this:
 *     ```
       <div id="content">
       	<div class="col-full">   
   
       		<div id="main" class="col-left">
       ```
   
 * I would like to add some php to it using the functions.php file (best practice)
   but I’m not sure how to do it if its possible. The php i would like to add is
 *     ```
       <?php
           			$page = "/";
           			$currentpage = $_SERVER['REQUEST_URI'];
           			if($page==$currentpage) {
           				gravity_form(1, true, false, false, '', false);
       			}
        		?>
       ```
   
 * Is there a hook or filter I can use in order to accomplish this?

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/add-php-to-indexphp/#post-2426927)
 * Not based on the code you gave above. All you could so is create a function and
   call that function within index.php.
 *  Thread Starter [ehoanshelt](https://wordpress.org/support/users/ehoanshelt/)
 * (@ehoanshelt)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/add-php-to-indexphp/#post-2426938)
 * Thank you for the reply!
 * I’ve had it like this and it works fine but I don’t like editing the index.php
   of the parent theme do to updates. I put the new index.php file in a child theme
   and made the edits. Is that the best solution then?
 *     ```
       <div id="content">
       	<div class="col-full">
       <?php
           			$page = "/";
           			$currentpage = $_SERVER['REQUEST_URI'];
           			if($page==$currentpage) {
           				gravity_form(1, true, false, false, '', false);
       			}
        		?>
       		<div id="main" class="col-left">
       ```
   
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/add-php-to-indexphp/#post-2426944)
 * Absolutely the best approach! 🙂
 *  [shirazdrum](https://wordpress.org/support/users/shirazdrum/)
 * (@shirazdrum)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/add-php-to-indexphp/#post-2426955)
 * Well the proper way of doing it would be to define your function in a function.
   php and put that in your child theme. then you can call it inside your index.
   php. That’s what the function.php is for. This way you are not crowding your 
   documents, and you can use the same function over and over without writing all
   the codes.
 * Example:
 *     ```
       <?php
       function blah_blah(){
       //your code}
       ?>
       ```
   
 * and then call the function like:
 * `<?php blah_blah(); ?>`
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/add-php-to-indexphp/#post-2426961)
 * Ok – agreed but that’s nit-picking. 😉 If you only want to use a given code snippet
   once, there is a very valid argument for not making it into a function.
 *  [shirazdrum](https://wordpress.org/support/users/shirazdrum/)
 * (@shirazdrum)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/add-php-to-indexphp/#post-2426974)
 * I confess, I’m super anal 🙂 The reason I got in the habit of making functions
   even for one argument is that when I build sites for clients, I try to eliminate
   the chances of them removing something that shouldn’t have. One single line of
   code is easier to understand than a long multiple line. And they are more petrified
   to dig into the function.php than editing the serving files. Believe it or not,
   even the ones that can’t read still mange to edit the files and it’s my job to
   fix things. The fact that it looks prettier doesn’t hurt either, but that’s at
   the end of my list 😛
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/add-php-to-indexphp/#post-2426981)
 * Hey – I’m something of a function fanatic myself but isn’t there something to
   be said about weighing “pretty code” against the (admittedly minute in this case)
   performance hit that’s incurred when code carries across 2 files? Added to which,
   ehoanshelt seems pretty clueful.
 *  [shirazdrum](https://wordpress.org/support/users/shirazdrum/)
 * (@shirazdrum)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/add-php-to-indexphp/#post-2426987)
 * 1 millionth of a second compare to 10 minutes of my trouble shooting time is 
   negligible. I look at the function.php as my private area that i’m the only editor.
   It comes useful if he tries to change the theme, then all he/she? needs to do
   is to take one look at the function list and it saves time again.
 * With all the times that it saves over 10 years, I can afford a bathroom break
   once in a while 🙂
 *  Thread Starter [ehoanshelt](https://wordpress.org/support/users/ehoanshelt/)
 * (@ehoanshelt)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/add-php-to-indexphp/#post-2427022)
 * Email box blew up lol I would use the functions.php file to do it like shirazdrum
   suggested but this is a one time use only thing and decided to do it inline for
   reasons esmi expressed. Additionally, the client for this website will never 
   get the appearance tab to touch the files to mess with them 😉
 * But thank you both for your time and consideration!
 *  Thread Starter [ehoanshelt](https://wordpress.org/support/users/ehoanshelt/)
 * (@ehoanshelt)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/add-php-to-indexphp/#post-2427205)
 * Marking topic resolved

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

The topic ‘Add php to index.php’ is closed to new replies.

## Tags

 * [add html](https://wordpress.org/support/topic-tag/add-html/)
 * [function.php](https://wordpress.org/support/topic-tag/function-php/)
 * [index.php](https://wordpress.org/support/topic-tag/index-php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 3 participants
 * Last reply from: [ehoanshelt](https://wordpress.org/support/users/ehoanshelt/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/add-php-to-indexphp/#post-2427205)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
