Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Display PHP output on a WordPress page


@salcode Met you at WC Lancaster. Looking to embed existing php code (not a snippet) in a WP page. Tried a few plugins. Suggestion?

My Thoughts

Displaying PHP output on a WordPress page can vary depending on where you want to display the output.

Display in the Content

I'd use a WordPress shortcode (I'm giving a talk on Creating Your First Shortcode at WordCamp Philly 2017).

Display Where There is a WordPress Action

This is most likely relevant if you're using the Genesis framework. In this case you can hook into the relevant action and put your relevant output in the function you attach to the hook.

Display Template Specific

Finally, you can modify the specific template being displayed. This is going to depend a lot on your theme. One important thing to remember is you can create a page template specific to the post_id, (e.g. page-375.php), see

Good Luck

I hope this helps. I'd be interested to hear how you ultimately solve the problem.

Copy link

felafel commented Oct 25, 2017

I ended up taking the page.php for the theme and making my own template page. I just inserted my code in the content area. I am thinking of adding the custom page code as a php include so that it is more clean and maintainable. Making it a widget was not working for me so tried the template and it did. I got the suggested steps from here:

P.S,. that wphierarchy site is cool.

Thanks for your reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment