Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/modernamusements/modern-amusement-snippets/archive/refs/heads/main.zipInsert header, footer and body snippets with conditional loading, a PHP error guard and JSON import/export. An improved "Insert Headers and Footers".
Version: 1.0.1 · Requires: WordPress 6.0+, PHP 7.4+ · License: GPL-2.0-or-later
🇩🇪 Deutsch
ModernAmusement Snippets fügt eigenen Code (HTML, CSS, JavaScript oder PHP) in den <head>, direkt nach dem öffnenden <body> oder in den Footer ein — mit fein granularem, bedingtem Laden pro Post Type, Post-ID, Template und URL-Regex sowie Logged-in/Besucher-Targeting.
Funktionen
- Bedingungen ohne Code — ein Snippet nur für bestimmte Post Types, Post-IDs, Templates oder URL-Muster aktivieren.
- PHP-Fehler-Guard — ein fehlerhaftes PHP-Snippet wird automatisch deaktiviert und im Admin gemeldet. Deine Seite geht durch ein Snippet nie kaputt.
- Syntax-Check beim Speichern — ungültiges PHP wird beim Speichern mit der Parser-Meldung abgelehnt.
- Body-open-Hook — ordentliche Unterstützung für
wp_body_open(). - JSON-Import/Export — Snippets in einem Klick oder per CLI zwischen Umgebungen (Staging → Live) verschieben.
- WP-CLI —
wp ma-snips list|status|export|import. - Hinterlässt keine Daten — zwei Optionen werden bei der Deinstallation entfernt.
- Übersetzungsbereit.
Installation
- Lade den Ordner
modern-amusement-snippetsnach/wp-content/plugins/hoch (oder installiere über Plugins → Installieren). - Aktiviere das Plugin.
- Öffne das neue Menü Snippets, klicke Neu hinzufügen, wähle Typ/Platzierung, füge Code ein und konfiguriere Bedingungen.
FAQ
Wie füge ich Google Analytics hinzu?
Snippet vom Typ HTML oder JS, Platzierung Header (<head>), optional per URL-Regex einschränken oder global lassen. Du kannst es auch mit „Nur Besucher" markieren, um eingeloggte Admins auszuschließen.
Mein PHP-Snippet wirft einen Fehler — was passiert? Das Snippet wird automatisch deaktiviert, ein Admin-Hinweis zeigt den Fehler, und der Rest der Seite funktioniert weiter. Fixiere den Code und aktiviere das Snippet erneut.
Warum erscheint mein Snippet nicht?
Prüfe den Status-Toggle, die Platzierung („Nach öffnendem <body>" erfordert wp_body_open() im Theme) und gesetzte Bedingungen (Post Type / ID / URL-Regex / eingeloggt).
Kann ich Snippets aus „Insert Headers and Footers" importieren? Du kannst manuell migrieren, indem du bestehenden Header-/Footer-Code in neue Snippets exportierst, oder deine Snippets als JSON hier speichern und auf der Zielseite re-importieren.
Gibt es einen WP-CLI-Befehl?
wp ma-snips list, wp ma-snips status <id> <on|off>, wp ma-snips export <file.json>, wp ma-snips import <file.json>.
Changelog
- 1.0.1 — Fix: Snippets rendern jetzt auf den echten
wp_head/wp_body_open/wp_footer-Hooks. Fix: URL-Regex-Bedingungen können über die UI gespeichert werden und gehen nicht mehr verloren. Fix: PHP-Snippets dürfen<?php ... ?>-Tags verwenden. Fix: neue Snippets bekommen eine ordentliche ID (vorher brach eine leere ID Edit/Toggle/Delete). Fix: Kommagetrennte Post-/ID- und Template-Listen in Bedingungsfeldern werden korrekt geparst. Fix: ein fehlschlagendes PHP-Snippet zerstört keine vom Theme geöffneten Output-Buffer. Fix: Reaktivieren eines deaktivierten Snippets leert die Fehlermeldung. Verbessert: sicherer Import (Uploads validiert, 2-MB-Limit). - 1.0.0 — Erstveröffentlichung.
🇬🇧 English
ModernAmusement Snippets inserts custom code (HTML, CSS, JavaScript or PHP) into the <head>, right after the opening <body> or into the footer — with fine-grained conditional loading per post type, post ID, template and URL regex, plus logged-in/visitor targeting.
Features
- Conditionals without code — activate a snippet only for specific post types, post IDs, templates or URL patterns.
- PHP error guard — a failing PHP snippet is deactivated automatically and reported in the admin. Your site never breaks because of a snippet.
- Syntax check on save — invalid PHP is rejected at save time with the parser message.
- Body-open hook — proper support for
wp_body_open(). - JSON import/export — move snippets between environments (staging → live) in one click or via CLI.
- WP-CLI —
wp ma-snips list|status|export|import. - No data left behind — two options are cleaned up on uninstall.
- Translations ready.
Installation
- Upload the
modern-amusement-snippetsfolder to/wp-content/plugins/(or install via Plugins → Add New). - Activate the plugin.
- Open the new Snippets menu, click Add New, choose type/placement, paste code and configure conditions.
FAQ
How do I add Google Analytics?
Snippet of type HTML or JS, placement Header (<head>), optionally restrict it with a URL regex or leave global. You can also mark it "Only visitors" if you want to exclude logged-in admins.
My PHP snippet throws an error - what happens? The snippet is deactivated automatically, an admin notice shows the error, and the rest of the site keeps working. Fix the code and activate it again.
Why is my snippet not appearing?
Check the status toggle, the placement ("After opening <body>" requires the theme to call wp_body_open()), and any configured conditions (post type / ID / URL regex / logged-in).
Can I import snippets from the legacy "Insert Headers and Footers"? You can migrate manually by exporting your existing header/footer code into new snippets, or store your snippets as JSON here and re-import them on the target site.
Is there a WP-CLI command?
wp ma-snips list, wp ma-snips status <id> <on|off>, wp ma-snips export <file.json>, wp ma-snips import <file.json>.
Changelog
- 1.0.1 — Fix: snippets now render on the real
wp_head/wp_body_open/wp_footerhooks. Fix: URL regex conditions can be saved from the UI and no longer get discarded. Fix: PHP snippets may use<?php ... ?>tags. Fix: new snippets get a proper ID (previously an empty ID broke edit/toggle/delete). Fix: comma-separated post/ID and template lists in the condition fields are parsed correctly. Fix: a failing PHP snippet no longer destroys output buffers owned by the theme. Fix: reactivating a deactivated snippet clears its error notice. Improve: safer import (uploads validated, 2 MB cap). - 1.0.0 — Initial release.
License
GPL-2.0-or-later — see LICENSE.
Author
Shady Tawfik · https://modern-amusement.dev/de