[wp-hackers] Finding post ID while in header

Robert Deaton false.hopes at gmail.com
Tue Mar 21 20:32:34 GMT 2006


On 3/21/06, CaptSolo <captsolo at gmail.com> wrote:
> Hi!
> I have registered a plugin action with add_action( 'wp-head',
> 'display_link' ) and now need to find the post ID from within that
> function:

s/wp-head/wp_head

> function display_link() {
>   if ( is_single() ) echo "<!-- Post ID = " . $post->ID . " -->\n";
> }
>
> Of course, there's no post ID echoed.

You forgot to global $post, and like Andy said, you want to pull your
data out of the $posts[0] object.

--
--Robert Deaton
http://somethingunpredictable.com


More information about the wp-hackers mailing list