Snipps
A simple html, css, js and php snippets plugin that automatically manages snippets with admin control.
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/omarhosamcodes/snipps/archive/refs/heads/dev.zipSnipps - WordPress Snippet Management Plugin
A powerful WordPress plugin that automatically manages code snippets (JavaScript, CSS, HTML, and PHP) with an intuitive admin interface for controlling where and when they are active.
Features
- 🔄 Automatic Snippet Detection: Automatically scans and detects snippet files in organized folders
- 🎛️ Admin Management Interface: Easy-to-use admin panel for managing snippets
- 📍 Location Control: Specify exactly where snippets should be loaded (head, footer, content, etc.)
- 🎯 Page Targeting: Control which pages/posts snippets appear on
- ⚡ Priority System: Set loading order with priority levels
- 🔧 Built-in Editor: Edit snippets directly from the WordPress admin
- 📊 Active/Inactive Toggle: Easily enable/disable snippets
- 🛡️ Security Conscious: Careful handling of PHP snippets with admin restrictions
Installation
- Upload the
snippsfolder to your/wp-content/plugins/directory - Activate the plugin through the 'Plugins' menu in WordPress
- Go to Tools > Snipps to manage your snippets
Directory Structure
After activation, the plugin creates the following directory structure:
wp-content/plugins/snipps/
├── snippets/
│ ├── js/ # JavaScript files (.js)
│ ├── css/ # CSS files (.css)
│ ├── html/ # HTML files (.html, .htm)
│ └── php/ # PHP files (.php)
├── admin/ # Admin interface files
├── includes/ # Core functionality
└── snipps.php # Main plugin file
Usage
Adding Snippets
-
File-based: Place your snippet files in the appropriate folders:
snippets/js/for JavaScript filessnippets/css/for CSS filessnippets/html/for HTML filessnippets/php/for PHP files
-
Admin Editor: Use the built-in editor in Tools > Snipps > Snippet Editor
-
Auto-scan: Click "Scan for Snippets" to detect new files
Managing Snippets
- Go to Tools > Snipps
- View all detected snippets in the management interface
- Toggle snippets active/inactive
- Click "Settings" to configure:
- Display Locations: Choose where snippets load (head, footer, etc.)
- Page Conditions: Select which pages to show snippets on
- Priority: Set loading order (lower numbers = higher priority)
Display Locations
- Head (wp_head): Loads in the
<head>section (default for CSS) - Footer (wp_footer): Loads before closing
</body>tag (default for JS) - Body Open (wp_body_open): Loads right after opening
<body>tag - Before Content: Loads before post/page content
- After Content: Loads after post/page content
Page Conditions
- All Pages: Show on all pages
- Home/Front Page: Only on homepage
- Single Posts: Only on individual blog posts
- Pages: Only on static pages
- Archives: Only on archive pages
- Admin Pages: Only in WordPress admin
Sample Snippets
The plugin includes sample snippets to demonstrate functionality:
JavaScript (js/sample-analytics.js)
// Sample Google Analytics tracking code
(function() {
var gaId = 'GA_MEASUREMENT_ID';
// Analytics implementation...
})();
CSS (css/sample-styles.css)
/* Custom highlighting and button styles */
.snipps-highlight {
background-color: #ffff99;
padding: 5px 10px;
border-radius: 3px;
}
HTML (html/sample-banner.html)
<!-- Promotional banner -->
<div class="snipps-promotional-banner">
<h3>Special Offer!</h3>
<p>Get 20% off all products this week!</p>
</div>
PHP (php/sample-custom-function.php)
<?php
// Custom WordPress functions
function snipps_custom_greeting($name = 'Visitor') {
return 'Hello, ' . esc_html($name) . '!';
}
add_shortcode('snipps_date', 'snipps_current_date_shortcode');
?>
Security Notes
- PHP Snippets: Only administrators can manage PHP snippets
- File Permissions: Ensure proper file permissions on snippet directories
- Code Review: Always review PHP snippets before activation
- Backup: Keep backups of important snippets
Admin Interface
Management Tab
- View all snippets with status indicators
- Quick toggle active/inactive status
- Access settings modal for each snippet
- Delete snippets (removes both file and database entry)
Editor Tab
- Built-in code editor with syntax awareness
- Create new snippets directly in admin
- Edit existing snippet files
- Auto-save functionality (optional)
Settings Tab
- Plugin documentation and usage tips
- Directory structure information
- Security guidelines
API and Hooks
Database Table: wp_snipps_settings
snippet_file: Relative path to snippet filesnippet_type: Type (js, css, html, php)is_active: Active status (0/1)location_rules: JSON rules for display locations and conditionspriority: Loading priority (lower = earlier)
Available Actions
snipps_before_snippet_output: Fired before outputting any snippetsnipps_after_snippet_output: Fired after outputting any snippet
Available Filters
snipps_snippet_content: Filter snippet content before outputsnipps_location_rules: Filter location rules before processing
Troubleshooting
Snippets Not Loading
- Check if snippet is active in admin
- Verify file exists in correct directory
- Check location rules and page conditions
- Scan for snippets to refresh database
PHP Errors
- Check PHP snippet syntax
- Verify WordPress function availability
- Review error logs
- Test snippets in staging environment
Permission Issues
- Check file permissions (644 for files, 755 for directories)
- Verify WordPress file upload permissions
- Ensure admin user capabilities
Changelog
Version 1.0.0
- Initial release
- Automatic snippet detection
- Admin management interface
- Location and page targeting
- Priority system
- Built-in editor
- Sample snippets
Support
For support, feature requests, or bug reports, please visit:
- GitHub: https://github.com/OmarHosamCodes/snipps
- Author: Omar Hosam contact@omarhosamcodes.com
License
This plugin is released under the GPL v2 or later license.