WordPress.org

Support

Support » How-To and Troubleshooting » get_the_ID() and $id Are not available in header.php, how can I get it?

get_the_ID() and $id Are not available in header.php, how can I get it?

  • Aw Guo
    Member

    @awflasher

    How can I get the post id in the header.php?

    It seems that the $id or get_the_ID can only be available in sidebar.php / footer.php but NOT in header.php

    Maybe it’s due to the header “doesn’t know” the id 🙂

    But how can I just get my ID in a header.php? Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Could you provide more specific information?
    What theme are you using? Which WP version? Your code? URL?

    I’m only guessing here: Does your sidebar.php reference a style sheet that header.php does not?

    I could not find any $id or get_the_ID anywhere in my sidebar/footer/header.php on my site. Or are you referring to a string?

    SMILE: You’re on camera!

    Aw Guo
    Member

    @awflasher

    Thanks Ripose, I post new new thread here:
    http://wordpress.org/support/topic/200320?replies=1

    Looking forward to your tips 🙂

    Rami Yushuvaev
    Participant

    @ramiy

    i was looking the get_the_ID() too, but there is no such function. sorry.

    Rami Yushuvaev
    Participant

    @ramiy

    sorry, here is the source of post-template.php:

    7 function the_ID() {
    8 global $id;
    9 echo $id;
    10 }
    11
    12
    13 function get_the_ID() {
    14 global $id;
    15 return $id;
    16 }

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get_the_ID() and $id Are not available in header.php, how can I get it?’ is closed to new replies.