Shopify safe practices for adding custom code
š§© Adding custom code in shopify
You can add custom code to a Shopify theme using either the built-in Custom Liquid sections/blocks in the theme editor for simple additions, or the Code Editor for direct, advanced file modifications.
When you edit code through:
Online Store ā Themes ā Edit Code
you are directly modifying the themeās core files.
š» Custom code includes any manual changes such as:
- Adding new functionality
- Changing layout or styling
- Modifying code of theme sections, snippets and assets (CSS, JS)
- Adding scripts, tracking, or integrations
- Creating custom snippets or assets
ā ļø Important to know
These modifications are not automatically preserved when a new version of the theme is released.
When updating a theme:
- Shopify installs a fresh version of the theme.
- Your previous custom changes must be manually reapplied.
š Theme editing safety guidelines
When making any theme code changes, always work in a safe environment to prevent breaking the live store.
ā Duplicate the theme before editing
Before adding custom code or modifying files, duplicate the current theme.
- Go to Online store ā Themes
- Click Duplicate on the live theme
- Make all changes in the duplicated version
ā Never edit the live theme directly
Working on a duplicate ensures that customers are not affected if something goes wrong.
ā Test changes in the duplicate theme
Verify layout, functionality, and integrations before publishing.
ā Easy rollback if issues occur
If errors appear, you can immediately return to the previous live theme without downtime.
ā What to check when a new theme version is released
When working with custom code in Shopify, itās important to understand how theme updates work, because updating a theme can overwrite custom changes youāve made.
Update theme ā draft & test workflow
When you see a new theme update, donāt publish it immediately. Follow this workflow to safely move the updated theme to live.
1ļøā£ Install theme as a draft (duplicate)
First thought: Never update directly on the live theme.
- Add the updated theme to the Theme library.
- Keep it as a draft (unpublished) version.
- This creates a safe testing environment.
2ļøā£ Initial testing (before adding custom changes)
Goal: Confirm the base theme works correctly before custom code is added.
UI checks
Review core storefront elements:
- Header navigation
- Product pages
- Cart functionality
- Filters & collections
- Mobile navigation & responsiveness
Apps & Integrations
Make sure integrations still load properly:
- Reviews apps
- Upsell / cross-sell tools
- Tracking scripts (GA, Meta Pixel, etc.)
- Subscription systems
š If something is already broken here, the issue is from the theme update ā not your customizations.
3ļøā£ Apply custom code
Next thought: Customizations should be added carefully.
- Manually transfer custom code and edits.
- Avoid copying entire files unless necessary.
- Re-apply only required customizations.
4ļøā£ Final testing
Now test the real scenario.
Verify after custom changes:
- UI elements display correctly
- Apps function as expected
- Checkout/cart behavior works
- Mobile and desktop both perform properly
- No console errors or layout breaks
5ļøā£ Publish
Final decision: Only go live when everything matches expectations.
- Publish the updated theme.
- Monitor the store after launch for any unexpected issues.
ā Best practices used by shopify developers
These practices help prevent issues during future theme updates.
ā Avoid modifying core theme files directly
Instead of editing core sections, create reusable snippets and include them.
ā Use Custom Liquid blocks when possible
Custom Liquid blocks are less likely to break during theme updates.
ā Isolate custom code
Keep all custom logic in separate files:
custom.jscustom.csssnippets/custom-*.liquid
ā Maintain a change log
Document all customizations so they can be easily reapplied after future updates.