How can I get the post id from within functions.php

Question

I’m building a function within functions.php

Within my function I want to make use of the post id of current post.
How do I do this?

The last thing I tried was this:

global $post ;
$id = $post->id ;

However, this returns an empty string.

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/how-can-i-get-the-post-id-from-within-functions-php/">

How can I get the post id from within functions.php</a>
0
Bob 1 week 0 Answers 21 views 0

Leave an answer