最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Show post object of any page in frontend

programmeradmin0浏览0评论

I want to see the content of the $post object in the front end. I want to do it via functions.php.

What I'm doing in function.php is:

global $post;
print_r($post);

But nothing shows up in the frontend. What am I doing wrong here?

I want to see the content of the $post object in the front end. I want to do it via functions.php.

What I'm doing in function.php is:

global $post;
print_r($post);

But nothing shows up in the frontend. What am I doing wrong here?

Share Improve this question edited May 3, 2020 at 15:52 Sven 3,6841 gold badge35 silver badges48 bronze badges asked May 3, 2020 at 6:17 Nayan ChowdhuryNayan Chowdhury 33 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Because in functions.php, it is too early to just run the print_r(), you may run it within a init hook like this:

Placing it inside theme's functions.php

add_action( 'init', 'test_trace' );
function test_trace() {
  global $post;
  print_r($post);
}
发布评论

评论列表(0)

  1. 暂无评论