WordPress powers half of the internet, from the most popular news sites to personal hobby bloggers, using WordPress as their favorite CMS platform daily.
One of the most powerful features of WordPress is that it can be easily extended with plugins or custom codes. These custom codes are widely available on different forums, tutorial sites, StackOverflow, and from plugin authors, among others. You can add these custom code snippets in two ways: by editing the functions.php file or using a Code Snippets plugin.
Popular use cases of Code Snippet plugins
- Adding custom PHP Code to extend functionalities
- Adding Header and footer codes (Google Analytics / Pixel / Ads codes)
- Custom CSS for specific post/page types
- Custom Javascript codes
- Dynamic Content to different types of places like before/after post content or footer
- Dynamic Shortcode
Why do we build FluentSnippets?
Long story short, we manage many websites for our products, which are mostly content sites. Our content team sometimes needs to add custom functionality for content placement and dynamic content blocks, and we need a code snippets plugin as we manage our WP files via Git. We tried almost all the existing code snippets plugins and could not settle on a single one due to the design decisions made by these plugin authors. Please read the full post to understand why we had to build a better solution for our own use.
Existing Code Snippets Plugins
There are many custom code snippet plugins in the market right now and most of them are super popular combinedly at least 4M+ websites use custom code snippet plugins.
Plugin Name | Active Installations | Pricing Model | Price |
---|---|---|---|
WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager | 2M+ | Freemium | From $99/Year |
Code Snippets | 900K+ | Freemium | From $40/Year |
Insert PHP Code Snippet | 100K+ | Free | — |
Woody code snippets – Insert Header Footer Code, AdSense Ads | 80K+ | Freemium | From $29/Year |
Header Footer Code Manager | 500K+ | Freemium | From $35/Year |
WPCodeBox | — | Premium | From 69/year |
Advanced Scripts | — | Premium | From 19.99/year |
These plugins solve the specific problems very well. I love WPCodeBox and Advanced Scripts. Both Plugins are managed by great founders and added many features in the last few years. Kudus to Ovidiu Maghetiu (WPCodeBox) & Abdelouahed Errouaguy (Advanced Scripts).
The internal architecture of these plugins
All of these plugins follow similar architecture to store and execute the code snippets and it’s not good and it’s dangerous in terms of performance and security.
Let’s see how these plugins work.
You see the problem in this design, right? All these code snippets plugins, store the snippets in the WP database, query all the snippets, and evaluate one by only on every WordPress request.
The cons of this architecture
- MySQL Database query on every request
- It’s a slow process to evaluate each snippet on the WP load
- The snippets can be altered by other plugins SQL injection Vulnerability
- It’s an anti-pattern of software architectural design. Codes should be on file like every software.
Design of FluentSnippets
At WPManageNinja, we invest considerable time and resources in building plugins that are super-optimized and well-designed. Each of our products aligns with a long-term vision, so every product we create must meet a certain level of code quality and architectural design, enabling us to manage them easily over a long period. If you are a developer, please check out the code base and internal designs of any of our plugins. I am sure you will be amazed by the design decisions we have made.
When designing the FluentSnippets plugin, we aimed to make it native and secure by design. Customer snippets should work exactly like WordPress core functions, or as if an experienced developer wrote code in a feature plugin.
Design of FluentSnippets Plugin
The design of FluentSnippets is intentionally super simple, as it should be. FluentSnippets stores code snippets in a flat file and uses code blocks in each snippet file to add metadata like a description, title, conditional logic, snippet type, and other details. We parse these data once and cache them in index.php, so there’s no need to parse these code blocks on every request. Then, at runtime, it simply includes those files in your selected action hook. Throughout this process, FluentSnippets runs zero database queries. In fact, there are no database queries in the entire plugin runtime.
With this native design, FluentSnippets is native, secure by design, and the most performant code snippets in this category.
FluentSnippets Features
In this very first version, we tried to add the features that it should have to use fully while keeping it super simple for all types of user bases.
File-based Snippets
Your snippets are safely saved in your file system and load natively with zero database queries, so it’s safe, secure, and ultra-fast.
Custom Code Snippets
Write your custom code snippets including PHP, JS, CSS, HTML, and more. Categorize your snippets with groups, tags, etc
Advanced Conditional Logics
Execute code snippets solely under specified conditions like post type, date, URL, user type, and many more.
Automatic Error Handling
The automatic error hander prevents common errors when adding custom snippets to ensure it never breaks your site.
Custom Shortcode
With custom shortcode of your snippets, you can create custom dynamic content blocks and use them across your site and manage them.
Stand-alone Mode
You can disable or uninstall FluentSnippets and still keep running your snippets in stand-alone mode. No lock-in, use it whenever you want.
Stand-alone Mode
The most interesting feature is the Stand-alone Mode. With this feature, you can add your snippets, activate the standalone mode, and then uninstall and delete the plugin. Despite this, your snippets will still run via the mu-plugins architecture. When you reactivate the plugin, you can manage your snippets as before.
The code editor
The code editor of FluentSnippets is simple. We have used codemirror javascript library to add the code editor. It does not have advanced features like auto-complete.
Powerful Smart Conditional Logics
We have added smart conditional logic to let you choose precisely where you want to execute your code. These conditional logics include
- User’s Login State or Role
- Type of Pages
- Post Types
- Taxonomy or Term-Based Rule
- By Page / Post URL
- Target Specific Page / Post / CPT
- Date Based Conditions
- FluentCRM Tag / Lists based rule of the current contact
These conditions are grouped-based, which means you can add multiple groups with a set of conditions, and if any of the groups match the conditions it will execute the snippet.
Powerful search and snippet Grouping
Many users add tons of snippets and finding & managing them is hard. For those types of users, we have added Snippet Group which works as a virtual folder and tags to find your desired snippet and manage. You can also search by description or title, and filter by tags. The full app is built with the Vue3 javascript library so it’s super fast by design.
Snippet Types
FluentSnippets has four types of snippets. You can choose the snippet type from the snippet type selection.
Functions – PHP Snippet: This snippet is for all the PHP code that you need to execute in specific areas like you would write in your theme’s functions.php file.
You can use this snippet type to create functions/classes, hook into other actions and filters, and more.
Content – PHP + HTML Snippet Type: This snippet type is used to insert content to different places like header, footer, after-post content, before-post content, etc. You can write php / html / js / css code in this snippet type.
CSS Snippet Type: You can use this snippet type to add custom CSS to your site.
JS Snippet Type: You can use this snippet type to add custom JS to your site.
Future of FluentSnippets
In every plugin we build, our aim is to solve problems for businesses and add immense value. We are releasing FluentSnippets with the same goal and vision. We will continue to improve, innovate, and add features that the community wants. There are a few things we plan to add to this website in the next few weeks.
- Code Snippets Library powered by the community and plugin authors
- Community Forum for Support and discissions
- Improve the Code Editor to support auto-complete
- Adding more snippet locations
- Adding more conditional logics
The source code for FluentSnippets is available on GitHub, and you are more than welcome to contribute to the code or the documentation. Alternatively, you can help us by recommending FluentSnippets to your friends and community. Together, let’s make WordPress more powerful and secure.
Nice job guys. 🙂
Thank you so much ❤️
What is the compatibility between Fluentsnippet and Oxygen builder?
This is the plugin every agency is looking for <3
Are you planning on adding SCSS/SASS coding capability for the CSS files? I’ve been writing in SCSS for so long I sometimes forget how to write basic CSS. 🙂
Can the location of the flat files be ste / changed
I really appreciate your design
The part of this article that describes the way competing snippet software works is somewhat incomplete with regards to WPCodeBox. The description under ‘The internal architecture of these plugins’ is correct in principle and the performance and security implications is correct.
However the article misses the important fact that WPCodeBox has a ‘Functional Plugin’ mode of operation that is developed to specifically change this behavior. The FP mode operates in a very similar manner to the ‘flat’ design of PHP snippets.
This mode is still officially declared an ‘experimental function’ but it works fine on multiple sites where I have tested it. This is documented on the WPCodeBox website, but because I am unfamiliar with moderation policies, I will not publish the direct link in case this blocks my comment.
In addition, since about autumn 2023, WPCodeBox also offers the ability to pack one or more snippets into a standalone plugin which can be deployed elsewhere. This means that WPCodeBox itself can be used locally as part of development and never be installed on production websites at all.
In the spirit of objectivity, I will really appreciate if the information I have provided is reviewed & confirmed, and the article is updated accordingly in due course.
Thanks guys. This makes my job easier <3
This is awesome! Many Thanks! I think I’ll take a closer look at the form plugin.
Very happy with it so far. No bloat or limited functionality, and the roadmap looks good.
Suggestion, maybe consider making the “Snippets” dashboard have a max-width, just like how the settings page has.
Currently, i feel like a fish watching it from my ultrawide monitor.
Amazing Job Shahjahan Jewel
Thank you
Thanks for this great design put into a free plugin!
I just found out about Fluent Snippets now. And I will not use any other Snippets plugin besides this!