Reading header.php/footer.php 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?
- The topic ‘Reading header.php/footer.php to a text string’ is closed to new replies.