• Resolved lwcorp

    (@lwcorp)


    I’ve found no documentation on it. PHP Snippets are clear, but what about the others, are they meant only for shortcodes or do they just make it easier to work by not needing wp_action / wp_filter?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Jeff Mankini

    (@jeffmankini)

    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

    Thread Starter lwcorp

    (@lwcorp)

    Thanks for the quick reply!

    You’ve mentioned Pro but regarding HTML Snippets it’s part of the free package. So if I use HTML to write <style> and </style> and <script> and </script> does it mean it bypasses the need for CSS and JS Snippets?

    Also, where does HTML, CSS, Script and also PHP-in-global mode Snippets put the code? Is it bottom of <head>? Top of <body>? Etc.

    Plugin Author Atif Riaz

    (@lightbulbman)

    Thanks for your follow-up!

    Regarding your question, HTML snippets allow you to add raw HTML directly to your site. However, for cleaner organisation, better management, performance and correct optimisations, you should use the dedicated CSS or JavaScript snippets for styling and scripts.

    As for code placement:

    • PHP snippets (global mode): Injected typically before the closing </body> tag.
    • HTML snippets: Placed in the body section, often in the header.
    • CSS snippets: Injected into the <head> dynamically.
    • JavaScript snippets: Injected into the <head> or just before </body>, depending on your settings.

    Code Snippets simplifies adding code without needing manual enqueues or theme file modifications.

    Hope this helps.

    Thread Starter lwcorp

    (@lwcorp)

    Thanks for the detailed explanations! Could you add those locations (head, body, etc.) to the FAQ?

    Meanwhile, can a single snippet be separated to different types? Otherwise, if you have 1 code that uses HTML, JS and CSS it would be cumbersome to divide it to 3 different snippets and risk forgetting to match their targeting.

    Plugin Author Shea Bunge

    (@bungeshea)

    Hi @lwcorp,

    Currently, snippets can only be one type, so adding a snippet that incorporates HTML, CSS and JS would be three separate snippets.

    We are definitely continuing to think about ways to improve this process and making it easier to combine different code types – please feel free to reach out with any suggestions!

    Thread Starter lwcorp

    (@lwcorp)

    Thanks for the clarification! Please write here if/when you add the locations (head, body, etc.) to the FAQ.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.