Support » Developing with WordPress » Last function that WP runs

  • MHalukK



    What’s the last single file/procedure/or function that runs the last for WP? The answer must hold true for all cases, themes. userroles etc.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    The shutdown_action_hook function is called last, which calls the “shutdown” action. If you want to hook something in to the shutdown, the “shutdown” action hook is the place to do it.

    The very, very last function called is wp_cache_close(), which is in fact a do nothing function, but remains there in case a plugin implements a different kind of object cache.



    Thank you for your reply. That’s an excellent reply. Do you also know of an internal procedure that runs for all cases/themes which will give me the option to output a oneliner which will output <iframe><iframe> code somewhere right before </body> or right after <body>

    I can do this in wp-config.php but then that <iframe></iframe> code goes out there before the <doc type>. And that is no good as far as creating a valid xhtml.

    I think the best way to handle what I want is to write a plug-in but I do now know how to write one.

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Because the theme controls output of the web page, there is no absolutely certain way to output code in the footer area.

    However, all themes should include the call to wp_footer() just before the ending /body code (or relatively close to it). Therefore, if you use the wp_footer action hook, you can hit like 95% of cases.

    function output_into_footer() {
    echo 'whatever';

    This is not guaranteed, but it usually works.



    Did you just give me a plug in code? Or if not, what is it? All I can tell it’s an action. hook. And as far as I know, that should go in the functions.php of the current theme, right? please confirm.

    I wish there was a single call which can output somewhere in between <body> and </body> and runs no matter what whatever the theme or template is… ( excluding rss feeds of course which are all xml ).

    so you are saying that since the output of the page is handled by template, there is really no way to guarantee to run a function/procedure from the wp core for all times?

    Also, what are the problems or consequences of putting an iframe as the first thing in html output, even before doc type?

    what is potantially so bad about this following;

    <iframe src=’’></iframe>
    <doc type….>


    assuming what’sin between <doc type and </html> is perfectly valid.

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Lot of questions there.

    1. You can put that code into a plugin, or into the theme’s functions.php file, or whatever. Not much difference.

    2. No, there is no guarantee. Themes do what they want. However, it’s a pretty good bet that things like wp_footer() are implemented in most themes.

    3. Well, doing stuff like that will make your page invalid, and some browsers won’t display your iframe, or might display the page incorrectly.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Last function that WP runs’ is closed to new replies.