How to use code injection on Ghost
Ghost's code injection feature allows you to add custom HTML, CSS, or JavaScript to your site's header or footer. Access it through Settings > Code injection in your Ghost admin dashboard to add tracking codes, custom styles, or scripts.
Prerequisites
- Ghost admin account with owner or admin permissions
- Basic HTML, CSS, or JavaScript knowledge
- Access to your Ghost admin dashboard
- Understanding of where code should be placed (header vs footer)
Step-by-Step Instructions
Access Ghost Admin Dashboard
yourdomain.com/ghost. Enter your admin credentials to access the backend interface.Navigate to Code Injection Settings
Choose Injection Location
- Header: CSS styles, meta tags, analytics tracking
- Footer: JavaScript widgets, performance tracking scripts
Add Your Custom Code
<style> tags. For JavaScript, use <script> tags. For example:<style>
.custom-class { color: #ff0000; }
</style>Save Your Changes
Verify Code Implementation
Ctrl+U or Cmd+U) to confirm your code appears in the correct location. Check browser developer tools for any console errors.Test Functionality
Common Issues & Troubleshooting
Code injection not appearing on site
Clear your browser cache and check if you're using a CDN that needs purging. Verify the code was saved correctly in Ghost admin.
JavaScript errors breaking site functionality
Check browser console for error messages. Remove recently added code and test incrementally. Ensure all <script> tags are properly closed.
CSS styles not applying correctly
Check CSS specificity issues and ensure styles aren't being overridden. Use !important declarations carefully or increase selector specificity.
Code appears in wrong location
Verify you're adding code to the correct injection area (header vs footer). Some scripts require specific placement to function properly.