Hi there
PHP, CSS, JavaScript, HTML, and Shortcode snippets serve different purposes. Here’s how they work:
PHP Snippets
- Runs PHP code just like in a theme’s
functions.php
file.
- Can be configured to run everywhere, admin only, frontend only, or on a specific hook.
- Avoids the need to manually add
add_action()
or add_filter()
if it’s set to run everywhere.
Shortcode Snippets
- A specialized form of PHP snippet meant to create shortcodes.
- Works similarly to adding a
shortcode.php
function in a theme or plugin.
- Typically includes
add_shortcode( 'your_shortcode', 'callback_function' );
automatically.
CSS Snippets
- Injects CSS into the site without needing to modify
style.css
or use a customizer.
- Added to the site’s header dynamically.
- Doesn’t require manual enqueuing.
JavaScript Snippets
- Injects JS into the site’s header or footer, depending on settings.
- Useful for adding tracking scripts, custom scripts, or modifying frontend behavior.
- Eliminates the need to enqueue scripts in
functions.php
.
HTML Snippets
- Allows adding raw HTML to a page.
- Often used for embedding iframes, forms, or other static content.
Do Non-PHP Snippets Need Actions/Filters?
- PHP snippets (non-shortcode): Don’t need
add_action()
or add_filter()
if set to run globally.
- Shortcode snippets: Are built for shortcodes and usually require
add_shortcode()
.
- JS/CSS/HTML snippets: No
wp_enqueue_script()
or wp_enqueue_style()
needed, as Code Snippets Pro injects them automatically.
In short, Code Snippets (Pro) simplifies adding PHP code without needing hooks manually and allows direct injection of CSS, JS, and HTML without modifying theme files or writing enqueues.
I hope this is helpful, but please do let me know if how I can assist further.
Best regards,
Jeff
The Code Snippets Team