Insert PHP Code Snippet is a free plugin that adds PHP snippet management to WordPress with one specific feature that Code Snippets does not have in its free version: shortcodes. You can execute a PHP snippet and output its result inside post content using a shortcode. This makes it useful for non-developer site owners who need to display dynamic content inline in pages or posts without writing a full plugin.
What Makes It Different
The key feature is shortcode execution. Create a PHP snippet that returns some output, and use the generated shortcode to display that output anywhere in your content. Examples:
- Display the current year in post content: create a snippet that returns date(‘Y’), use the shortcode where you want it
- Show logged-in user’s name in a page: snippet returns wp_get_current_user()->display_name
- Display a custom field value inline: snippet returns get_post_meta(get_the_ID(), ‘custom_field_name’, true)
- Show conditional content based on user role: snippet checks current_user_can() and returns appropriate text
Code Snippets free does not generate shortcodes from PHP snippets – you would need Code Snippets Pro for this. For this specific use case, Insert PHP Code Snippet provides it free.
Creating a Snippet
Go to PHP Code Snippets -> Add New PHP Code Snippet. Give the snippet a name and write your PHP code. The plugin automatically generates a shortcode in the format [xyz-ips snippet=”Snippet-Name”]. Copy this shortcode and use it in any post or page.
Practical example – display the user’s first name if logged in, or nothing if not:
$user = wp_get_current_user();
if ($user->ID) {
return 'Welcome, ' . esc_html($user->user_firstname) . '.';
}
return '';
Need a developer to implement this cleanly? Describe what you need and get a free estimate.
Hooks and Actions
Insert PHP Code Snippet also supports running code on WordPress hooks, not just via shortcodes. In the snippet settings, select whether the snippet runs via shortcode only, or hooks into a WordPress action/filter. This gives similar functionality to Code Snippets’ scope system.
Limitations
Insert PHP Code Snippet is simpler than Code Snippets and intentionally so. It lacks:
- Import/export between sites
- Multiple snippet types (CSS, JS, HTML)
- Safe mode recovery URL
- Tagging or advanced organisation
- Revision history
For sites that just need a few functional PHP snippets and shortcode output, it covers the use case. For larger snippet libraries, Code Snippets or WPCodeBox are more appropriate.