Can I run custom php on specific pages in wordpress?

If you are using a child or custom theme, I encourage you to look at the Codex’s Template Hierarchy.

The short answer to your question is yes, you can run custom code on any page you’d like.

The longer answer is still yes, but it’s a bit more involved in what your end product is going to look like.

I’ll paste in the part about pages from the aforementioned page:

The template file used to render a static page (page post-type). Note that unlike other post-types, page is special to WordPress and uses the following path:

  • custom template file – The page template assigned to the page. See get_page_templates().
  • page-{slug}.php – If the page slug is recent-news, WordPress will look to use page-recent-news.php.
  • page-{id}.php – If the page ID is 6, WordPress will look to use page-6.php.
  • page.php
  • singular.php
  • index.php

So, you have the ability to create any one of these custom templates, and apply them to your page, running any code you need.