2017-07-25 00:06
浏览 277


I need to add my own custom PHP script to all Wordpress pages of my blog.

I am not referring to adding PHP onto a single page (which can be done with a plugin).

Essentially, this is what I need to do:

  • Add a snippet of code directly to Wordpress script that handles display of posts.
  • The snippet needs to be able to grab a ID of the post.

Can someone show me the best way to do this?

This is what I need to figure out:

  • Which of the Wordpress php files handles the display of the Wordpress posts (is it post-template.php by any chance?)

  • How to grab the Post ID using PHP? I found the page which says this could be the possible way, is that correct way of getting the Post ID?

    $id = get_the_ID();

图片转代码服务由CSDN问答提供 功能建议

我需要将自己的自定义PHP脚本添加到我博客的所有Wordpress页面。 \ n



  • 将一段代码直接添加到处理 display的Wordpress脚本 帖子。
  • 该片段需要能够获取帖子的ID。

    有人能告诉我最佳方式 要做到这一点?


    • 哪些Wordpress php文件处理 Wordpress posts的显示(它是post-template.php吗?)

    • 如何使用PHP获取帖子ID? 我发现这个页面说明了这可能是获取帖子ID的正确方法吗?

      $ id = get_the_ID(); \ n

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douhuxi4145 2017-07-25 00:11

    for single post, it single.php and to get post ID

    $post = get_post();
    $id = $post->ID;
    解决 无用
    打赏 举报

相关推荐 更多相似问题