This plugin has been closed and is no longer available for download.

PHP Code for posts


Currently in rapid deployment testing – fixing bugs and quirks with older versions of PHP

PHP Code for posts allows you to add your own PHP code to posts, pages, custom post types (posts) and even sidebars without the need for custom templates

The plugin enables a shortcode and options page so you can add your code to the admin options page and then output it in your post using shortcodes

Multiple code snippets can be used on a post, and multiple posts can use the same code snippet, allowing you to re-use code.

The shortcodes can be used to also display plain HTML content, allowing you to add in iframe, objects, areas and other tags that are removed by the post editor

The plugin also contains a variable array which you can add variables to for use between snippets called $_var and is available though the global variable $PHPPC which is an object, so its $PHPPC::$_vars[]

Parameter Variable Extraction: When this option is enabled, you will be able to access the parameters passed to a snippet using their name. For example in the snippet [php snippet=x param=test=hello] you will be able to directly access $test in your code snippet for the value of “hello”, rather than needing to do $_parameters["test"]

It is important that the PHP Variable Naming Conventions are followed when using this option otherwise it could have some unexpected results. (see:

New for 1.1.1

The plugin’s shortcode can also accept parameters using the param attribute, the value should be a string of name=value pairs, separated by &s, for example [php snippet=2 param="var1=val1&var2=val2"]. Within your snippet, the parameters are assigned a $_parameters array, for example echo $_parameters["var1"]; //outputs "val1"

New for 1.2.0

The plugin’s snippet editor now has better formatting, and supports AJAX saving for snippet updates (request by eneasgesing)

New for 2.0.x

  • Refreshed interface
  • Custom shortcode name
  • Translation support
  • Expansion of the parameter system

New For 2.1.x

  • Multisite!

Multisite update comes with more options to make handling your multisite setup simplier.

These options can only be changed on blog id 1 (the master site)

  • New Options

Allow Custom Snippets for sub-sites?

This option allows you to enable or disable the ability for sub-sites to create, edit and use their own snippets

Allow sharing of snippets between sites

This option allows you to enable or disable the ability for sub-sites to share their own snippets and to use other sub-site’s snippets via the new shortcode

Allow per-site options for multisite

This option allows you to enable or disable the ability for sub-sites to change options specific to their site such as the main shortcode, and ajax saving

Change the multisite Shortcode.

In keeping with the ability to change the original shortcode, this opion allows you to change the new multisite shortcode to what ever you fancy. Just don’t try making it the same as the single site, it wont work!

  • New Shortcode

With the new multisite comes a new shortcode.

This shortcode allows the loading of shared snippets from other members of your multisite setup.

Simply pass the blog_id and the snippet to load, and if the snippet exists and is shared, it will load it.

By default, blog_id is 1, the master site, and sub sites can always use shared master site snippets


  • The plugin options menu
  • The edit snippet screen


  1. Download the plugin to your computer
  2. Extract the contents
  3. Upload (via FTP) to a sub folder of the WordPress plugins directory
  4. Activate the plugin in the admin dashboard.


You mentioned a variable array to assign variables to for use between snippets, how do I do this?

To assign variables to the array, use the following code:
global $PHPPC;
$PHPPC::$_vars[“myvaridentifier”] = $myvar;

and to read a variable from the array use this code:
global $PHPPC;
$myvar = $PHPPC::$_vars[“myvaridentifer”];

AJAX update keeps failing

One of the main causes of a failed AJAX update is because nothing has actually changed in any of the fields.

My snippet doesn’t work

One common error is an error in the eval’d code, this is more down to a syntax / parse error in the PHP snippet, rather than the plugin itself, double check your code and make sure its correct.

Your explanation of the multisite feature doesn’t make sense

Email me your question! I may be able to explain it better!

No other questions yet!



Per Fraser Ad Astra

I inherited a site with php splattered all over, with many similar pages and lots of repeated code. The php was in the pages and widgets and eval’d by a plugin.

Now I have beautiful refactored code, all out of the pages and widgets, and safely in snippets. The mechanism for using $PHPPC for shared variables is nice too, and made refactoring SO much easier.

The facility to export and import snippets is nice too, as I was able to try things out on my own server, then stick them up on the hosting, with just a few clicks.

Your plugin has saved the day. And you are a fellow Scot too.

We like that.

Great Plugin, Excellent Service

A small issue in the latest version of this plugin, which was caused by my old version of php was solved within minutes of me notifying the author!

Friendly and extremely fast response and a quick solution makes what was already a great plugin even greater,

You can rely on it!

Hacked the post after plugin activation

Im very sorry but as I installed this plugin only the post which I have used with the shortcode explained in your documentation some one edited my post with hacked bla bla bla

Your Plugin is insecure!

Great plugin and …some sugestions

A very great plugin
I’m doing a migration from PHP Snippets which has been abandoned to your plugin.
I’ve more than 150 snippets to migrate…it’s a very long job.

So, I’ve some suggestions :

– Can you envisage to implement a functionality to import snippet from a txt file (ie : files used by PHP Snippets for example)

– Can you add a button on the interface like « save and add new »

– Can you add a filter functionality (my snippets are categorized…. so, it should be interesting to select a group of snippets)

Thanks by advance if you cans take in consideration some of mu suggestion but, anyway, thank for your good job


Read all 58 reviews

Contributors & Developers

“PHP Code for posts” is open source software. The following people have contributed to this plugin.


Translate “PHP Code for posts” into your language.

Interested in development?

Browse the code, check out the SVN repository, or subscribe to the development log by RSS.



  • Initial Release
  • No changes


  • Added missing functionality for delete single snippet
  • Tested for WP 3.6
  • Added class functions for getting and setting shared variables (get_variable and set_variable)


  • added parameters for snippits


  • Fix for php warning handle_extra_shortcode (thanks to paul_martin)


  • Fix for the table not being created in a multi-site installation (thanks to dondela and mediagent)
  • Fix for the parameter variables not splitting correctly because of html entity encoding (thanks to eoh1)


  • Ajax saving for updating code snippets (ajax save for initial add still to be implemented) (request by eneasgesing)
  • Richer snippet editor using Codemirror (request by eneasgesing)


  • Confirmed support for latest version of WP (4.2.1) just in case you were wondering


  • Refreshed interface
  • Custom shortcode name
  • Translation support


  • Fixed issue in options class with incompatibility with array accessing a function return i.e. foo()[‘bar’]


  • Based on support queries, I have added in an option to disable ajax saving for snippets


  • Based on feedback, I have removed an anonymous function


  • Fixed issue with parameters not passing through correctly


  • Removed ? : shorthand ifs


  • Fixed issue with compatibility with PHP 5.2


  • Fixed another issue with compatibility with PHP 5.2


  • Fixed the stripping of backslashes from code


  • Fixed another issue with compatibility with PHP 5.2 – seriously, why is anyone using it?!


  • More translation support


  • Notice Error Fix
  • Parameter Variable Extraction


  • Multisite! Improved multisite support including shared options and snippets
  • Confirmed support for 4.5.1


  • Fixed a massive issue with non-multisites not working (sorry!)


  • Fixed a massive issue with non-multisites not working (sorry!)


  • You asked for an export/import, I made it happen

  • removed short array syntax


  • Reduction in menu tab size
  • Added ability to move the menu into the tools menu
  • Added the ability to assign slugs to snippets, and call snippets by slug


  • Added slug to the exporter/importer


  • Db Delta fix

  • removal of short array syntax – Upgrade your php versions people!