WP Manifestindependent plugin directory
manifest / developer / snippet-companion

Snippet Companion - Headers & Footers

Insert custom CSS and JavaScript snippets into header and footer with advanced targeting options for specific pages and posts.

by Iqbal Hossain · github.com/wp-shark/snippet-companion

★ 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/wp-shark/snippet-companion/archive/refs/heads/main.zip

A powerful WordPress plugin that allows you to insert custom CSS and JavaScript snippets into your website's header and footer with advanced targeting options.

Features

  • Easy Snippet Management: Add, edit, and delete CSS and JavaScript snippets from a clean admin interface
  • Location Control: Choose to insert snippets in header or footer
  • Advanced Targeting: Display snippets on all pages, specific pages/posts, home page, or custom conditions
  • Active/Inactive Toggle: Easily enable or disable snippets without deleting them
  • Priority System: Control the order of snippet execution
  • Code Editor: Built-in syntax highlighting with WordPress Code Editor
  • Clean UI: Post-like interface for managing snippets
  • Performance Optimized: Lightweight and efficient code execution

Installation

  1. Upload the snippet-companion folder to the /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress
  3. Navigate to 'Snippets' in the WordPress admin menu

Usage

Creating a New Snippet

  1. Go to Snippets > Add New
  2. Enter a name for your snippet
  3. Choose snippet type (CSS or JavaScript)
  4. Enter your code in the code editor
  5. Select location (Header or Footer)
  6. Choose where to display (All Pages, Home Page, Posts, Pages, or Specific Pages)
  7. Set priority (lower number = higher priority)
  8. Check "Active" to enable the snippet
  9. Click "Publish"

Managing Snippets

  • View All Snippets: Go to Snippets > All Snippets
  • Toggle Status: Click the toggle switch in the Status column to activate/deactivate
  • Edit Snippet: Click "Edit" under the snippet name
  • Delete Snippet: Click "Delete" under the snippet name (with confirmation)
  • Filter by Status: Use the "All", "Active", or "Inactive" filters

Display Options

  • All Pages: Snippet displays on every page of your site
  • Home Page Only: Only on the front page
  • All Posts: Only on single post pages
  • All Pages: Only on WordPress pages
  • Specific Pages/Posts: Enter comma-separated page/post IDs

File Structure

snippet-companion/
├── snippet-companion.php       # Main plugin file
├── composer.json              # Composer configuration
├── README.md                  # This file
├── includes/
│   ├── Hooks.php             # Centralized hook registration
│   ├── Admin/
│   │   ├── Admin.php         # Admin functionality
│   │   └── SnippetList.php   # List table class
│   ├── Database/
│   │   └── Schema.php        # Database schema
│   ├── Frontend/
│   │   └── Frontend.php      # Frontend output
│   ├── Helpers/
│   │   └── Utils.php         # Helper functions
│   └── Traits/
│       └── Singleton.php     # Singleton trait
├── templates/
│   └── admin/
│       ├── list-page.php     # Snippets list page
│       └── add-edit-page.php # Add/edit snippet page
└── assets/
    ├── css/
    │   └── admin.css         # Admin styles
    └── js/
        └── admin.js          # Admin JavaScript

Database Schema

The plugin creates a custom table wp_snippet_companion with the following structure:

  • id: Unique identifier
  • name: Snippet name
  • description: Optional description
  • snippet_type: Type (css or js)
  • code_content: The actual code
  • location: Where to insert (header or footer)
  • display_on: Display conditions
  • specific_pages: Comma-separated page/post IDs
  • priority: Execution order
  • status: Active (1) or Inactive (0)
  • created_at: Creation timestamp
  • updated_at: Last update timestamp

Development

Requirements

  • PHP 7.4 or higher
  • WordPress 6.0 or higher
  • MySQL 5.6 or higher

Setup Development Environment

# Install Composer dependencies
composer install

# Generate autoload files
composer dump-autoload

Hooks & Filters

Actions

  • snippet_companion/before_init - Runs before plugin initialization
  • snippet_companion/after_init - Runs after plugin initialization

Filters

Currently, no public filters are available. This may change in future versions.

Changelog

1.0.0

  • Initial release
  • CSS and JavaScript snippet support
  • Header and footer placement
  • Advanced targeting options
  • Active/inactive toggle
  • Priority system
  • WordPress Code Editor integration

License

This plugin is licensed under the GPL-2.0-or-later license.

Support

For support, please visit the WordPress.org support forums or contact the plugin author.

Credits

Developed following WordPress coding standards and best practices.