I would like to see the dump data of $post object in any page. So which code snippet to add in functions.php?
global $post;
print_r ($post);
This is not working. Please suggest.
I would like to see the dump data of $post object in any page. So which code snippet to add in functions.php?
global $post;
print_r ($post);
This is not working. Please suggest.
Share Improve this question asked May 3, 2020 at 13:29 Nayan ChowdhuryNayan Chowdhury 33 bronze badges1 Answer
Reset to default 0Adding:
global $post;
print_r ($post);
alone, won't work in functions.php (becuase WP's core functions etc wouldn't be loaded). It would inside a relevant template file, but not in functions.php.
To make it work in functions.php, you need to do it inside an function that is hooked to an appropriate hook. The "appropriate" hook may depend on what $post
object you're looking for (e.g. that of a single post or a post type archive), but a good way to target many situations is the wp_head hook, e.g:
add_action('wp_head', function(){
global $post;
print_r ($post);
});