Title: Adding php code before DocType
Last modified: August 21, 2016

---

# Adding php code before DocType

 *  [srower](https://wordpress.org/support/users/srower/)
 * (@srower)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/adding-php-code-before-doctype/)
 * I need to include a bit of php code as the very first line on my blog pages. 
   This code triggers a membership login and needs to appear before doctype on the
   page (I know this is not good coding, but I have no choice but to do it this 
   way at the moment). I placed the at the top of the header.php file of my theme;
   however, two things are going on. 1. I cannot see the code when I view the page
   source (which seems odd to me) and 2. Regardless of not being able to see it 
   in page source, the script does appear to be triggering in IE and Chrome, but
   not in Firefox. Am I doing this wrong by adding it to the header.php file? Any
   thoughts are appreciated.

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

 *  [WPyogi](https://wordpress.org/support/users/wpyogi/)
 * (@wpyogi)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/adding-php-code-before-doctype/#post-4424863)
 * Why do you say the code has to be above the DOCTYPE?
 *  Thread Starter [srower](https://wordpress.org/support/users/srower/)
 * (@srower)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/adding-php-code-before-doctype/#post-4424866)
 * Yes, as I stated, I know it’s wrong and if I didn’t have to do it, I wouldn’t
   be asking for assistance. It involves a programmer hired by a client who has 
   created a total mess for me to work with, but I have no choice at the moment.
   The only way to get what he did to work is to put this code before DocType. Any
   assistance to accomplish this would be great. Thanks.
 *  [CrouchingBruin](https://wordpress.org/support/users/crouchingbruin/)
 * (@crouchingbruin)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/adding-php-code-before-doctype/#post-4424888)
 * > 1. I cannot see the code when I view the page source (which seems odd to me)
 * You cannot view the PHP code by doing a **view source** because PHP is executed
   on the server. For example, if you write this PHP code:
 *     ```
       <?php
       echo "Hello world!";
       ?>
       ```
   
 * All you are going to see when you do a **view source** is **Hello world!**.
 * > 2. Regardless of not being able to see it in page source, the script does appear
   > to be triggering in IE and Chrome, but not in Firefox.
 * Again, PHP executes on the server, so it doesn’t matter which browser the user
   is using. The output created by the PHP may be rendered differently on different
   browsers, especially if there is something wrong with what is being generated.
   I usually find that Chrome is more forgiving than Firefox when an ending paragraph
   tag or an ending DIV tag is left off.
 * Can you paste a sample of the PHP code that’s supposed to go before the DOCTYPE?
   If it’s too long, put it into a [pastebin](http://pastebin.com/) and provide 
   a link.
 *  Thread Starter [srower](https://wordpress.org/support/users/srower/)
 * (@srower)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/adding-php-code-before-doctype/#post-4424892)
 * Thanks so much for the response. The code is simple:
    <?php require_once(‘enable_protection.
   php’); ?> which triggers a script file in the same directory.

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

The topic ‘Adding php code before DocType’ is closed to new replies.

 * 4 replies
 * 3 participants
 * Last reply from: [srower](https://wordpress.org/support/users/srower/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/adding-php-code-before-doctype/#post-4424892)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
