WP Manifestindependent plugin directory
manifest / developer / snipps

Snipps

A simple html, css, js and php snippets plugin that automatically manages snippets with admin control.

by Omar Hosam · github.com/omarhosamcodes/snipps · website

0stars
0forks

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.zip

Snipps - 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

  1. Upload the snipps folder to your /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress
  3. 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

  1. File-based: Place your snippet files in the appropriate folders:

    • snippets/js/ for JavaScript files
    • snippets/css/ for CSS files
    • snippets/html/ for HTML files
    • snippets/php/ for PHP files
  2. Admin Editor: Use the built-in editor in Tools > Snipps > Snippet Editor

  3. Auto-scan: Click "Scan for Snippets" to detect new files

Managing Snippets

  1. Go to Tools > Snipps
  2. View all detected snippets in the management interface
  3. Toggle snippets active/inactive
  4. 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 file
  • snippet_type: Type (js, css, html, php)
  • is_active: Active status (0/1)
  • location_rules: JSON rules for display locations and conditions
  • priority: Loading priority (lower = earlier)

Available Actions

  • snipps_before_snippet_output: Fired before outputting any snippet
  • snipps_after_snippet_output: Fired after outputting any snippet

Available Filters

  • snipps_snippet_content: Filter snippet content before output
  • snipps_location_rules: Filter location rules before processing

Troubleshooting

Snippets Not Loading

  1. Check if snippet is active in admin
  2. Verify file exists in correct directory
  3. Check location rules and page conditions
  4. Scan for snippets to refresh database

PHP Errors

  1. Check PHP snippet syntax
  2. Verify WordPress function availability
  3. Review error logs
  4. Test snippets in staging environment

Permission Issues

  1. Check file permissions (644 for files, 755 for directories)
  2. Verify WordPress file upload permissions
  3. 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:

License

This plugin is released under the GPL v2 or later license.