PHP Script within wordpress theme

PHP does not ever display in source, if things are working correctly. PHP executes on the server. If things are working the way they should you never see the PHP source.

I don’t know what your conditions are for this project, but the most straightforward way to access a script is to make a custom page template for it.

You would …

  1. create your template,
  2. add your script to that template,
  3. create a page from the backend
  4. and assign that page to the template you created

The second way to access your script would be to create a shortcode. It sounds like you have already come across this solution but were trying to use a plugin. I expect it was some kind of “execute this PHP” shortcode, which is overly complicated. Creating a shortcode is easy. A bare-bones shortcode would look like:

function bare_bones_sample_shortcode($atts,$content) {
   return "test simple shortcode";
}
add_shortcode('bbss', 'bare_bones_sample_shortcode');

You would then write [bbss] in your post body and “test simple shortcode” should show up. In your case you’d want to put your script in place of that return. The $atts and $content let you do things like `[bbss id="abc"]This is cool content[/bbss]. I don’t know enough about your script to write anything more elaborate though.

There may be other ways to trigger that script, such as hooking it to something– the_content maybe– but again, without knowing more about the script I can’t really elaborate. You could even access it over AJAX.

Leave a Comment