Support » Themes and Templates » [Resolved] In page.php: how do I access/update whatever “get_header()” generates?

[Resolved] In page.php: how do I access/update whatever “get_header()” generates?

  • In page.php:

    Immediately after the typical opening line of…

    <?php get_header(); ?>

    …I want to be able to access the HTML that was generated by the get_header function. I would like to do a str_replace() function on certain elements within that header output.

    Any code suggestions on 1.) accessing and then 2.)updating that header output?

Viewing 7 replies - 1 through 7 (of 7 total)
  • That would be in the header.php template for that theme.

    Stepping Into Templates
    Stepping Into Template Tags
    Template Hierarchy

    Thanks, but let me rephrase the question:

    – I am in page.php
    – I do “get_header()” so that header.php can generate its html
    – I now am back in page.php at the line immediately after the “get_header()” statement

    My question is: how do I access the output that was generated by the “get_header()” funtion?

    Is there some global variable like “$page_output” that contains all the HTML that was generated so far?


    Not that I know of, but someone else might want to comment on that:



    Justin Tadlock


    WordPress God

    Is there some global variable like “$page_output” that contains all the HTML that was generated so far?

    No, there’s not a way to do that, at least as far as I know.

    But, you should tell us what it is you’re trying to accomplish overall. There might be a better way to do it than the current method you’re trying.

    I have one page within my WP site that requires HTTPS, so I updated .htaccess to force that page to be HTTPS. This works OK except that some of the generated WP code (either via plugins or whatever) are generated with HTTP rather than HTTPS.

    These non-HTTPS references are causing IE browsers to display the warning message:

    Do you want to view only the webpage content that was delivered securely?

    Here is a partial dump of a VIEW SOURCE of the page in question, and it shows the HTTP references that are causing IE to display the above warning message (note that I changed the references to the live domain in the source view below to ‘somedomain.com’):

    SomeDomain.com<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
    <head profile="http://gmpg.org/xfn/11">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>My HTTPS Contact Form</title>
    <link rel="stylesheet" href="https://www.somedomain.com/wp-content/themes/mytheme/style.css" type="text/css" media="screen" />
    <link rel="pingback" href="http://www.somedomain.com/xmlrpc.php" />
    <link rel="shortcut icon"  href="https://www.somedomain.com/wp-content/themes/mytheme" />
    <meta name='robots' content='noindex,nofollow' />
    <link rel="alternate" type="application/rss+xml" title="SomeDomain.com &raquo; Feed" href="http://www.somedomain.com/feed/" />
    <link rel="alternate" type="application/rss+xml" title="SomeDomain.com &raquo; Comments Feed" href="http://www.somedomain.com/comments/feed/" />
    <link rel="alternate" type="application/rss+xml" title="SomeDomain.com &raquo; Contact Comments Feed" href="http://www.somedomain.com/contact/feed/" />
    <link rel='stylesheet' id='sociable-front-css-css'  href='http://www.somedomain.com/wp-content/plugins/sociable/sociable.css?ver=2.9.1' type='text/css' media='' />
    <link rel='stylesheet' id='wp-pagenavi-css'  href='https://www.somedomain.com/wp-content/plugins/wp-pagenavi/pagenavi-css.css?ver=2.50' type='text/css' media='all' />
    <script type='text/javascript' src='https://www.somedomain.com/wp-includes/js/jquery/jquery.js?ver=1.3.2'></script>
    <script type='text/javascript' src='https://www.somedomain.com/wp-content/themes/mytheme/includes/mytheme.js?ver=2.9.1'></script>
    <script type='text/javascript' src='https://www.somedomain.com/wp-includes/js/comment-reply.js?ver=20090102'></script>
    <script type='text/javascript' src='https://www.somedomain.com/wp-content/themes/mytheme/scripts/contact-form.js?ver=1.0'></script>
    <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://www.somedomain.com/xmlrpc.php?rsd" />
    <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://www.somedomain.com/wp-includes/wlwmanifest.xml" />
    <link rel='index' title='SomeDomain.com' href='http://www.somedomain.com' />
    <meta name="generator" content="WordPress 2.9.1" />
    <!-- All in One SEO Pack 1.6.10 by Michael Torbert of Semper Fi Web Design[311,346] -->
    <link rel="canonical" href="http://www.somedomain.com/contact/" />
    <!-- /all in one seo pack -->
    <body class="page page-id-38 page-template page-template-contact-form-php logged-in">
    <div id="page">
    	<div id="header">
    		<div id="header_inner">
    			<h1><a href="http://www.somedomain.com/">SomeDomain.com</a></h1>
    			<div class="description">&quot;My Title&quot;</div>
    			<div id="header_links"><a href="../">home</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://www.somedomain.com/about">about</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://www.somedomain.com/contact">contact</a>&nbsp;&nbsp;
    ...remainder of code truncated for convenience

    My thought was that if I could intercept the generated HTML before it is sent to the browser then I could change the problematic HTTP to HTTPS.

    Any suggestions as to how I can get rid of the HTML that is causing the IE warning message?

    I found a solution (thanks to Moff at stackoverflow.com) whereby I use php output buffering, as in his example:

    // example from php.net
    function callback($buffer) {
      // replace all the apples with oranges
      return (str_replace("apples", "oranges", $buffer));
    <p>It's like comparing apples to oranges.</p>
    <?php ob_end_flush(); ?>
    /* output:
       <p>It's like comparing oranges to oranges.</p>

    In my situation the page I was working with was a contact form template, so I added equivalent code and was able to intercept the HTML and use str_replace to manipulate it (changing the culprit http reference to https) before sending it on to the user.

    In my instance the “culprit” was the sociable plugin, but I suspect that many plugins could similarly trip the IE warning message.

    One drawback to this technique is that the entire page is buffered before it is sent to the user, but in my case the transmission delay is negligible.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] In page.php: how do I access/update whatever “get_header()” generates?’ is closed to new replies.