Ready to get started?Download WordPress

Plugin Directory

PHP Snippets

Provides an interface for developers to easily add PHP code to posts and widgets via selectable shortcodes.

= My Snippets are not showing up!=

Make sure your files use the .snippet.php extension and that you have correctly configured your PHP Snippets directory under Settings --> PHP Snippets. The directory has to be a full path, e.g. /home/myuser/public_html/snippets

Only *.snippet.php files inside your PHP Snippet directory OR inside of an immediate subfolder will be selectable. Deeper hierarchies are not supported.

The reason that only *.snippet.php files are listed is because some scripts may involve multiple PHP files: by giving only one file the *.snippet.php extension, you can control which file is the "main" file.

What information needs to be in the Snippet header?

Your Snippets should include an information header in the same way that WordPress plugins and themes, but it's much simplified. Include a Description: and a Shortcode: to indicate a description and a sample shortcode, respectively.

Description: Generates a link to a post or page based on its ID.
Shortcode: [link id=123]Click here[/link]

Look at the examples in the php-snippets/snippets directory for some examples.

What inputs does my Snippet get?

Anything you pass in your shortcode will be passed to your Snippet. E.g. [mySnippet x="123" y="Llama"] will make the variables $x and $y available in your Snippet (they would contain "123" and "Llama", respectively). The $content variable is reserved for when you use a full tag, e.g. [mySnippet]My content goes here[/mySnippet] would make$content` contain the text "My content goes here".

What should my Snippet output?

Your Snippet should print its output (not return it). This makes it easy for you to include reusable bits of HTML.

Technically speaking, your code doesn't have to output anything -- some scripts may only need to execute on the back-end and remain out of site.

There's a Bug in the Plugin!

Check to make sure the bug is actually in the plugin and not in one of your Snippets. This plugin acts mostly as a pass-through, and the error messages should be confined to your code (hopefully not mine). If there's something goofy going on, please let me know by filing a bug report.

Requires: 3.0 or higher
Compatible up to: 3.5.2
Last Updated: 2013-7-21
Downloads: 13,943


4 stars
4.8 out of 5 stars


1 of 3 support threads in the last two months have been resolved.

Got something to say? Need help?


Not enough data

0 people say it works.
0 people say it's broken.