CLI tool to scaffold a WordPress theme powered by React, TypeScript, and Vite
npm install create-wordpress-theme-tsbash
npx create-wp-theme-ts my-site
cd my-site
npm run dev
`
Features
- ā” Vite - Lightning-fast HMR and optimized builds
- āļø React 18 - Latest React with concurrent features
- š TypeScript - Full type safety out of the box
- š
styled-components - CSS-in-JS styling
- šØ Font Awesome - Icon library included
- š§ ESLint + Prettier - Code quality tools pre-configured
- š¦ WordPress Theme Zip - Production build outputs a ready-to-deploy theme
Usage
$3
Simply run without arguments to enter interactive mode:
`bash
npx create-wp-theme-ts
`
You'll be prompted for:
- Project name
- WordPress theme name
- Author name
- Project description
$3
`bash
npx create-wp-theme-ts [options]
`
Options:
- --skip-install - Skip automatic npm install
- --skip-git - Skip git repository initialization
Examples:
`bash
Create with custom name
npx create-wp-theme-ts my-awesome-theme
Skip npm install (useful if you want to use yarn/pnpm)
npx create-wp-theme-ts my-site --skip-install
Skip both install and git init
npx create-wp-theme-ts my-site --skip-install --skip-git
`
Project Structure
After scaffolding, your project will have this structure:
`
my-site/
āāā php/ # WordPress PHP files
ā āāā functions.php # Theme functions
ā āāā index.php # Main WordPress template
āāā public/ # Static assets
ā āāā images/ # Image files
ā āāā style.css # WordPress theme stylesheet
āāā src/ # React source code
ā āāā components/ # React components
ā ā āāā Layout.tsx # Main layout component
ā āāā pages/ # Page components
ā ā āāā Home.tsx # Home page
ā ā āāā About.tsx # About page
ā ā āāā NotFound.tsx # 404 page
ā āāā styles/ # CSS files
ā ā āāā global.css # Global styles
ā āāā App.tsx # Main App component
ā āāā index.tsx # Entry point
ā āāā vite-env.d.ts # Vite type definitions
āāā .eslintrc.json # ESLint configuration
āāā .gitignore # Git ignore rules
āāā .prettierrc # Prettier configuration
āāā index.html # HTML template
āāā package.json # Project dependencies
āāā tsconfig.json # TypeScript configuration
āāā vite.config.ts # Vite configuration
`
Available Scripts
In your generated project, you can run:
$3
Starts the development server at http://localhost:8080.
Features hot module replacement for instant feedback while developing.
$3
Creates an unminified build in the dist/ folder.
$3
Creates a development build with source maps.
$3
Creates an optimized production build and generates wordpress-custom-theme.zip in the dist/ folder.
$3
Preview the production build locally before deploying.
Deploying to WordPress
1. Run the production build:
`bash
npm run build:prod
`
2. Locate the generated zip file:
`
dist/wordpress-custom-theme.zip
`
3. In your WordPress admin panel:
- Go to Appearance ā Themes ā Add New ā Upload Theme
- Upload wordpress-custom-theme.zip
- Click Install Now
- Click Activate
Customization
$3
1. Create a new component in src/pages/:
`tsx
// src/pages/Contact.tsx
function Contact() {
return Contact Page;
}
export default Contact;
`
2. Add the route in src/App.tsx:
`tsx
import Contact from './pages/Contact';
// Inside Routes:
} />;
`
3. Add navigation link in src/components/Layout.tsx:
`tsx
Contact
`
$3
This template uses styled-components for styling:
`tsx
import styled from 'styled-components';
const Button = styled.button
;
`
$3
Create a .env file in your project root:
`env
VITE_API_URL=https://api.example.com
VITE_APP_TITLE=My Site
`
Access them in your code:
`tsx
const apiUrl = import.meta.env.VITE_API_URL;
`
Note: Only variables prefixed with VITE_ are exposed to your code.
WordPress Theme Customization
$3
Edit public/style.css to update the WordPress theme metadata:
`css
/*
Theme Name: Your Theme Name
Author: Your Name
Author URI: https://yoursite.com
Description: Your theme description
Version: 1.0.0
License: MIT
*/
`
$3
Edit php/functions.php to add WordPress functionality:
`php
// Register a navigation menu
register_nav_menus(array(
'primary' => __('Primary Menu'),
));
// Add custom post type support
// Add widget areas
// etc.
``