jjj
jjj

Reputation: 2672

How to Insert PHP Code in all WordPress Posts

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:

Can someone show me the best way to do this?

This is what I need to figure out:

Upvotes: 0

Views: 934

Answers (2)

Johannes
Johannes

Reputation: 67778

It depends on the theme. Very simple themes might use index.php for all pages, others use single.php for the display of single posts, and there are a lot more possibiites, also secondary templates (template parts) which are included in the primary templates and contain part of the post. Have a look in the theme folder.

Inside all of these, the posts are always inside "the loop". This page has the explanation and some useful examples: https://codex.wordpress.org/the_loop HTH

Upvotes: 0

ewwink
ewwink

Reputation: 19154

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

$post = get_post();
$id = $post->ID;

Upvotes: 1

Related Questions