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

  1. Aw Guo
    Posted 7 years ago #

    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!

  2. Ripose
    Posted 7 years ago #

    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!

  3. Aw Guo
    Posted 7 years ago #

    Thanks Ripose, I post new new thread here:

    Looking forward to your tips :)

  4. Rami Yushuvaev
    Posted 7 years ago #

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

  5. Rami Yushuvaev
    Posted 7 years ago #

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

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

Topic Closed

This topic has been closed to new replies.

About this Topic