Snippet Companion - Headers & Footers
Insert custom CSS and JavaScript snippets into header and footer with advanced targeting options for specific pages and posts.
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.zipA 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
- Upload the
snippet-companionfolder to the/wp-content/plugins/directory - Activate the plugin through the 'Plugins' menu in WordPress
- Navigate to 'Snippets' in the WordPress admin menu
Usage
Creating a New Snippet
- Go to Snippets > Add New
- Enter a name for your snippet
- Choose snippet type (CSS or JavaScript)
- Enter your code in the code editor
- Select location (Header or Footer)
- Choose where to display (All Pages, Home Page, Posts, Pages, or Specific Pages)
- Set priority (lower number = higher priority)
- Check "Active" to enable the snippet
- 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 identifiername: Snippet namedescription: Optional descriptionsnippet_type: Type (css or js)code_content: The actual codelocation: Where to insert (header or footer)display_on: Display conditionsspecific_pages: Comma-separated page/post IDspriority: Execution orderstatus: Active (1) or Inactive (0)created_at: Creation timestampupdated_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 initializationsnippet_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.