• intersting observation.
    seems I cannot get the ID of a post in my header.php <head> section?

    doing this
    <meta property="og:image" content="<?php swapthumbURL(); get_the_ID(); ?>
    in the header returns empty.
    doing it after the body tag returns expected result.

    (note: the function swapthumbURL() is placed in my functions.php file, and returns the url to a post’s thumbnail at the 50×50 size, thus it “swaps” the post thumbnail out for it’s smaller brother.

    so, how can I use a function in the head section which calls to the ID of the post?
    some small bit of magic appreciated.
    cheers.
    vince.

Viewing 1 replies (of 1 total)
  • Thread Starter vincej

    (@vincej)

    hmm, issue solved.
    seems that if you place the call before
    <?php wp_head(); ?>
    it does not work.
    if you place it after right after and before the </head it works great.

    Strange that the_ID() will not return above the wp_head wheras the other template tags like the_title and others do.

    perhaps a bug… or something I didn’t understand in how WP handles the ID of the current page before wp_head is called.

    kinda makes sense, but inquiring minds wouldn’t mind knowing why.
    so
    Why can the_title work before wp_head but the_ID doesn’t? or is it just me and my blog?

Viewing 1 replies (of 1 total)
  • The topic ‘get ID of post/page in header, cannot do, is there a trick?’ is closed to new replies.