Editing Theme Code
To customize your Ghost theme beyond the available settings, youβll need to edit the theme files directly. This guide explains how to safely modify your themeβs code.
Before You Begin
Before editing your theme code, keep these important points in mind:
- Make backups: Always back up your theme before making changes
- Test changes: After modifications, thoroughly test your site on different devices
- Theme updates: Custom changes may be lost when updating your theme
- Code knowledge: Basic understanding of HTML, CSS, and Handlebars is helpful
Editing Theme Files
Follow these steps to edit your theme files:
-
Download a copy of your theme from Ghost Admin:
- Go to Settings β Theme
- Click on the active themeβs dropdown menu
- Select Download to get a ZIP file of your theme
-
Unzip the theme archive to a folder on your computer
-
Use a code editor of your choice (such as Visual Studio Code, Sublime Text, or Atom) to make the required changes
-
Common files you might want to edit:
assets/custom.css
for custom stylesassets/custom.js
for custom scripts.hbs
files for template modifications (e.g.,post.hbs
,index.hbs
,page.hbs
)default.hbs
for changes that affect the entire site
-
Once you have finished editing the code, you need to re-zip the theme directory:
- On macOS, right-click on the theme folder and choose Compress from the context menu
- On Windows, right-click on the theme folder, select Send to, and then choose Compressed (zipped) folder
-
Upload the modified theme to your Ghost site:
- Return to Settings β Theme
- Click Upload theme and select your modified ZIP file
- Activate the uploaded theme
Common Theme Customizations
Here are some common theme customizations you might want to make:
Modifying CSS Styles
To change colors, fonts, spacing, or other visual elements:
- Add custom styles in the
assets/custom.css
file - Use browser developer tools to identify the elements you want to modify
Changing Templates
To modify how specific pages or posts are displayed:
- Find the relevant template file (e.g.,
post.hbs
,page.hbs
) - Make your changes while preserving the Handlebars syntax (
{{...}}
) - Be careful not to remove essential Ghost functionality
Adding Custom Scripts
To add JavaScript functionality:
- Add custom scripts in the
assets/custom.js
file - Test thoroughly to ensure they donβt conflict with existing functionality
Using Theme Partials
Many themes use partials (reusable code snippets) stored in the partials/
directory. Editing these files will affect all pages that use them.
Testing Your Changes
After making changes:
- Check your site on different devices and browsers
- Verify that all Ghost features still work correctly
- Test pagination, navigation, and special features
Reverting Changes
If something goes wrong:
- Return to Settings β Theme
- Upload your backup theme ZIP file
- Activate the original theme
By following these guidelines, you can safely customize your Ghost theme to meet your specific needs while maintaining its core functionality.