Title: Reading header.php/footer.php to a text string
Last modified: August 20, 2016

---

# Reading header.php/footer.php to a text string

 *  Resolved [UnlockTheMind](https://wordpress.org/support/users/unlockthemind/)
 * (@unlockthemind)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/reading-headerphpfooterphp-to-a-text-string/)
 * I am attempting to read the results of the executed header.php/footer.php files
   as a string of html. Here’s the scenario:
 * There are pages in the site that are developed in a .net environment but they
   want to share common headers/footers across the entire domain. They wish to have
   WordPress be the repository for this code and any time there is an update have
   a PHP cURL call to a .net web service and feed it the new HTML for the header/
   footers.
 * I tried calling **get_header()** but that does not return a string (as I anticipated)
   so then I tried this test solution in functions.php:
 *     ```
       function write_header() {
       	$header_content = file_get_contents(get_bloginfo('wpurl').'/index.php' );
       	$fp = fopen('c:\header.txt', 'a+');
       	fwrite($fp, $header_content);//just testing the output, this will be a cURL call eventually.
       	fclose($fp);
       }
       add_action( 'wp_update_nav_menu', 'write_header' );
       ```
   
 * It seems to be a very heavy handed method of getting the HTML since I’ll have
   to do a lot of string manipulation to parse out the pieces I want. Is there a
   simpler way of doing this that I’m missing?

Viewing 1 replies (of 1 total)

 *  Thread Starter [UnlockTheMind](https://wordpress.org/support/users/unlockthemind/)
 * (@unlockthemind)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/reading-headerphpfooterphp-to-a-text-string/#post-3128420)
 * In case anyone comes across this thread looking to do the same thing. I worked
   through an answer on [stackoverflow](http://stackoverflow.com/questions/12964043/reading-wordpress-header-php-footer-php-to-a-text-string)
   
   Basically create a page that contains just the header/footer and then read it
   using `file_get_contents(get_bloginfo('wpurl').'/update/' )` where /update/ is
   the page with just the header/footer. Alternately you could use `wp_remote_get()`

Viewing 1 replies (of 1 total)

The topic ‘Reading header.php/footer.php to a text string’ is closed to new replies.

## Tags

 * [footer](https://wordpress.org/support/topic-tag/footer/)
 * [footer.php](https://wordpress.org/support/topic-tag/footer-php/)
 * [get_header](https://wordpress.org/support/topic-tag/get_header/)
 * [header](https://wordpress.org/support/topic-tag/header/)
 * [header.php](https://wordpress.org/support/topic-tag/header-php/)
 * [string](https://wordpress.org/support/topic-tag/string/)

 * 1 reply
 * 1 participant
 * Last reply from: [UnlockTheMind](https://wordpress.org/support/users/unlockthemind/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/reading-headerphpfooterphp-to-a-text-string/#post-3128420)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
