• Hi,

    I am trying to write a plugin which adds a particular HTTP header when posts and pages are displayed, depending on the value of a custom field for the post.

    Unfortunately, at the time when the header lines are printed, the function the_ID() does not yet work. It is set within “the loop” only (I could not yet find a good reason why the display of a single post needs that loop construct).

    What function do I have to call to get the ID of a requested post or page at a time where headers have not yet been printed (e.g. from an init action)?

Viewing 1 replies (of 1 total)
  • Its hard to say without knowing what you are hooking to but you can often do global $posts; and get that information.

Viewing 1 replies (of 1 total)
  • The topic ‘How to get the page ID before headers are sent’ is closed to new replies.