A modern portfolio blog built with Gatsby, featuring static site generation (SSG) with optional WordPress data integration. This project demonstrates how to build a fast, SEO-friendly blog that can work with or without WordPress.
This project serves as a portfolio blog template that combines the best of both worlds:
- Gatsby's performance: Static site generation for blazing-fast loading
- WordPress's content management: Optional content updates through WordPress admin
- SEO optimization: Pre-rendered pages with proper meta tags
- Modern UI: Responsive design with smooth animations
- Zero Configuration: Works out of the box with local fallback data
Perfect for developers, designers, and content creators who want a fast, maintainable blog with optional content management.
# Clone the repository
git clone https://github.com/tomcomtang/wordpress-gatsby.git
cd wordpress-gatsby
# Install dependencies
npm install
# Build and deploy (no environment variables required!)
npm run build
Preview the project: https://wordpress-gatsby.edgeone.app/
- Frontend: Gatsby 4 (React-based static site generator)
- Content Management: WordPress REST API (optional)
- Styling: CSS Modules with custom styles
- Comments: Giscus (GitHub Discussions integration, optional)
- Deployment: EdgeOne, or any static hosting
WordPress API (Optional) β Gatsby Build Time β Static HTML/CSS/JS β CDN
- Build Time Data Fetching: Gatsby fetches WordPress data during build (if configured)
- Fallback Data: Uses local static data if WordPress is not configured
- Static Generation: Creates pre-rendered HTML pages
- No Runtime API Calls: All content is embedded in the static files
- Fast Loading: Pages load instantly from CDN
src/
βββ components/ # React components
β βββ HeroSection.js # Homepage hero section
β βββ AboutMe.js # About section
β βββ header.js # Navigation header
β βββ layout.js # Main layout wrapper
βββ data/
β βββ fallbackData.js # Local fallback data (used when WP is not configured)
βββ pages/ # Page components
β βββ index.js # Homepage
β βββ posts.js # Blog posts list
β βββ post/[slug].js # Individual post pages
β βββ comments.js # Comments page (only shown if Giscus is configured)
β βββ contact.js # Contact page
βββ services/
β βββ wordpressApi.js # WordPress API utilities
βββ styles/ # CSS modules and styles
This project is designed to work out of the box without any configuration. All environment variables are optional:
# WordPress Configuration (Optional)
# If not set, the site will use local fallback data from src/data/fallbackData.js
GATSBY_WORDPRESS_URL=https://your-wordpress-site.wordpress.com
# Giscus Comments Configuration (Optional)
# If any of these are missing, the Comments menu will NOT be displayed
GATSBY_GISCUS_REPO=your-username/your-repo-name
GATSBY_GISCUS_REPO_ID=your-repo-id
GATSBY_GISCUS_CATEGORY_ID=your-category-id
If GATSBY_WORDPRESS_URL
is NOT set:
- β Site works perfectly with local fallback data
- β All pages and functionality are available
- β
Content comes from
src/data/fallbackData.js
- β No external dependencies
If GATSBY_WORDPRESS_URL
is set:
- β Site fetches content from your WordPress site at build time
- β Uses the same data structure as fallback data
- β
Automatically generates
posts-list.js
with latest content - β Falls back to local data if WordPress is unavailable
- WordPress.com:
https://your-site.wordpress.com
- Self-hosted:
https://your-domain.com
For local development and testing, you can set environment variables directly:
# macOS/Linux
export GATSBY_WORDPRESS_URL=https://your-wordpress-site.wordpress.com
# Windows (Command Prompt)
set GATSBY_WORDPRESS_URL=https://your-wordpress-site.wordpress.com
# Windows (PowerShell)
$env:GATSBY_WORDPRESS_URL="https://your-wordpress-site.wordpress.com"
# Then start the development server
npm run develop
Comments functionality is completely optional:
- If NO Giscus variables are set: Comments menu is hidden, no comment functionality
- If ALL three Giscus variables are set: Comments menu appears, full comment functionality
- Go to Giscus
- Configure with your GitHub repository
- Copy the configuration values to your
.env
file:GATSBY_GISCUS_REPO
: Your repository name (e.g., "username/repo")GATSBY_GISCUS_REPO_ID
: Your repository IDGATSBY_GISCUS_CATEGORY_ID
: Your category ID
- The Comments menu will automatically appear in the navigation
- Comments will appear on blog posts and the comments page
Testing: Visit /giscus-test
to verify your Giscus configuration is working correctly.
If you choose to use WordPress, configure your site to match the data structure used in the fallback data. Reference src/data/fallbackData.js
for the exact format.
- ACF Custom Fields: If you use the ACF plugin (recommended for paid/self-hosted WordPress), create custom fields for your categories or pages. The field structure and content should match the examples in
fallbackData.js
. - Category Description: For WordPress.com free plans, paste JSON data into the category description field (see below for format).
When using ACF, configure your custom fields to match the fallback data structure. For example, for the hero section:
{
"basic": {
"name": "Your Name",
"title": "Welcome Message",
"description": "Your introduction text",
"avatar": "https://your-avatar-url.com"
},
"buttons": [
{
"text": "View Posts",
"link": "/posts",
"type": "primary"
},
{
"text": "Contact Me",
"link": "/contact",
"type": "secondary"
}
]
}
Tip: Always refer to
src/data/fallbackData.js
for the latest data structure examples. Your ACF field group should use the same keys and nesting as the fallback data.
{
"basic": {
"name": "Your Name",
"title": "Welcome Message",
"description": "Your introduction text",
"avatar": "https://your-avatar-url.com"
},
"buttons": [
{
"text": "View Posts",
"link": "/posts",
"type": "primary"
},
{
"text": "Contact Me",
"link": "/contact",
"type": "secondary"
}
]
}
{
"title": "About Me",
"description": "Your detailed about section content",
"image": "https://your-image-url.com",
"skills": ["Skill 1", "Skill 2", "Skill 3"]
}
{
"title": "Get In Touch",
"description": "Contact form description",
"email": "[email protected]",
"phone": "+1 234 567 8900",
"address": "Your address here"
}
{
"socials": [
{
"name": "GitHub",
"url": "https://github.com/yourusername",
"icon": "github"
},
{
"name": "LinkedIn",
"url": "https://linkedin.com/in/yourusername",
"icon": "linkedin"
}
]
}
{
"title": "Comments Policy",
"description": "Your comments policy and guidelines",
"rules": [
"Be respectful and constructive",
"No spam or self-promotion",
"Stay on topic"
]
}
{
"text": "Β© 2025 Your Name. All rights reserved.",
"links": [
{
"text": "Privacy Policy",
"url": "/privacy"
}
]
}
[
{
"name": "Frontend Development",
"level": 90,
"color": "#61dafb"
},
{
"name": "Backend Development",
"level": 85,
"color": "#f7df1e"
}
]
[
{
"title": "Project Name",
"description": "Project description",
"image": "https://project-image-url.com",
"url": "https://project-url.com",
"technologies": ["React", "Node.js", "MongoDB"]
}
]
- Node.js 16+
- npm or yarn
-
Clone the repository
git clone https://github.com/tomcomtang/wordpress-gatsby.git cd wordpress-gatsby
-
Install dependencies
npm install
-
Start development server
npm run develop
The site will work immediately with local fallback data!
-
Optional: Configure WordPress
- Create a
.env
file - Add your
GATSBY_WORDPRESS_URL
- Restart the development server
- Create a
-
Optional: Configure Comments
- Add Giscus environment variables to
.env
- Comments menu will appear automatically
- Add Giscus environment variables to
npm run build
The built site will be in the public/
directory, ready for deployment.
- Modify
src/styles/
for global styles - Update component-specific CSS modules
- Customize colors and fonts in CSS variables
- With WordPress: Update content through WordPress admin
- Without WordPress: Edit
src/data/fallbackData.js
- Modify components in
src/components/
- Update page templates in
src/pages/
- Customize navigation in
src/components/header.js
Use the "Deploy to EdgeOne" button above for one-click deployment.
Upload the contents of the public/
directory to any static hosting service.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Gatsby team for the amazing static site generator
- WordPress for content management
- Giscus for GitHub Discussions integration
- All contributors and users of this template
Remember: This template works perfectly without any configuration! All environment variables are optional. Start with npm install && npm run develop
and you'll have a fully functional portfolio blog.