Can I Run My Own PHP Scripts Within Joomla or WordPress Pages?

This is a common question, actually — and the answer is an enthusiastic Yes!

→ For WordPress, check out the “Insert PHP” plugin.

→ For Joomla, check out the “Jumi” extension.

I prefer working in Joomla myself, so here are some notes about using Jumi:

While Jumi has quite a lot of functionality, the easiest way to use it (IMHO) is to basically “include” your custom PHP script by using their syntax. In the article or module where you want your script to run, you would just need to call the PHP script, like so:

{jumi [path to your script]}
// For example, if you keep your scripts at
// yoursite.com / programs
// and your script is called "go.pph"
// then the code you would put in your article
// or module would look like this:
{jumi [programs/go.php]}

So, in the above second example, it assumes that you have a file called “go.php” that lives at [root] / programs. You may want to locate your scripts elsewhere, of course. Just adjust the path accordingly.

From there, the script will run just the same as if it were on any other web site. Super easy!!

Passing Variables to Your Scripts

There are two ways to do send value to your PHP scripts when using Jumi. The first is via normal URL GETs and POSTs. I find an easy way to do this is to setup a Joomla article on a hidden menu. For example, start a new article on your site, and make a hidden menu, and add that article to it with the alias “widgets”. Thus, you would now be able to view that article at the address: www.mysite.com/widgets. From there, you simply pass along values as usual, such as this GET:

mysite.com/widgets?id=123

Then, in your PHP, you just do something like:

$thisWidget = $_GET['id'];

… and then you run your script passing $thisWidget to your SQL. (Of course, you would want to properly validate such a thing, as always.) As noted, you can $_POST data to your scripts as usual, too.

(Of course, if you’re working in a Joomla context, you can leverage JInput to better receive your variables. But, that’s a whole different conversation.)

A Second Method

You can also send values to your script another way. In your include script, you can insert additional arguments after the script declaration. For example:

{jumi [path/to/script/script.php][bob][mary]}

Jumi saves the arguments you send along in an array called $jumi. So, above we have sent “bob” and “mary”. Thus, in your PHP, you would grab those like this:

$person01 = $jumi[0]; // that would be bob
$person01 = $jumi[1]; // that would be mary

I admit this part isn’t the most intuitive because you’re locked into a specific indexing there for that $jumi array! But, it does work. I usually use the previously mentioned method of passing along values via GETs and POSTs. But, sometimes it’s handy or necessary to do this the second way.


Jim Dee heads up Array Web Development, LLC in Portland, OR. He’s the editor of “Web Designer | Web Developer” magazine and a contributor to many online publications. You can reach him at: Jim [at] ArrayWebDevelopment.com. Photo atop piece is adapted from “Source code security plugin” by Christiaan Colen (Flickr, Creative Commons). Please 💚 this article if you liked it (by clicking the heart icon below), as it really helps.