G-Snippets
Simple WordPress plugin to add Gutenberg Snippets to either post content.
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/dgaitan/g-snippets/archive/refs/heads/main.zipReadme
G-Snippets
A WordPress plugin for managing reusable content snippets that can be injected into posts and pages using the Gutenberg editor.
Description
G-Snippets allows you to create reusable content snippets using the native Gutenberg editor. Each snippet can be configured to display on specific post types, before or after content, with priority-based matching when multiple snippets apply to the same post.
Features
- Gutenberg Editor: Create snippets using the full Gutenberg block editor
- Flexible Display Rules: Configure snippets to display on specific post types
- Location Control: Choose to display snippets before or after post content
- Priority System: When multiple snippets match, the one with the lowest priority number wins
- Include/Exclude Posts: Fine-tune snippet display with include and exclude lists
- Active Toggle: Enable or disable snippets without deleting them
- Comprehensive List View: View all snippet settings at a glance in the admin list table
Requirements
- WordPress 5.0 or higher
- Advanced Custom Fields (ACF) plugin (required)
Installation
- Upload the
g-snippetsfolder to the/wp-content/plugins/directory - Activate the plugin through the 'Plugins' menu in WordPress
- Ensure Advanced Custom Fields (ACF) is installed and activated
- Navigate to 'G-Snippets' in the admin menu to start creating snippets
Usage
Creating a Snippet
- Go to G-Snippets > Add New in the WordPress admin
- Enter a title for your snippet
- Use the Gutenberg editor to create your snippet content
- Configure the snippet settings in the "Snippet Settings" meta box:
- Post Types: Select which post types this snippet should apply to (default: Posts only)
- Location: Choose "Before Content" or "After Content" (default: After)
- Priority: Set a priority number (lower numbers = higher priority, default: 10)
- Active: Toggle to enable/disable the snippet
- Include Posts: Optionally select specific posts where this snippet should appear
- Exclude Posts: Optionally select specific posts where this snippet should NOT appear
- Publish the snippet
How Snippets Match Posts
A snippet will be displayed on a post if:
- The post's type matches one of the snippet's selected post types
- The snippet is active
- If an "Include Posts" list is set, the post must be in that list
- The post must NOT be in the "Exclude Posts" list
If multiple snippets match a post, only the one with the lowest priority number will be displayed.
Priority System
- Lower numbers = higher priority
- Example: A snippet with priority 5 will display over a snippet with priority 10
- Default priority is 10
Technical Details
- Custom Post Type:
g_snippet - Uses ACF for field management
- Hooks into
the_contentfilter with priority 15 - Caches snippet queries for performance
Changelog
1.0.0
- Initial release
- Custom post type with Gutenberg support
- ACF field integration
- Content injection with priority system
- Include/exclude post functionality
- Custom admin list table columns
Support
For issues, questions, or contributions, please visit the plugin repository.
License
GPL v2 or later