A modern WordPress starter theme built with webpack, Tailwind CSS, and React, designed for developers who want a clean, efficient starting point for custom WordPress development.
Clone this repository into your WordPress themes directory:
cd wp-content/themes
git clone https://github.com/your-username/base-theme.git ./your-theme-name
Install dependencies:
cd your-theme-name
npm install
Build assets:
# Development with watch mode
npm run watch
# Production build
npm run build:prod
Activate the theme in WordPress admin panel
npm start
- Start development server with HMRnpm run watch
- Watch for changes and rebuildnpm run build
- Development buildnpm run build:prod
- Production build with optimizationsCreate your component in src/js/components/
:
// src/js/components/YourComponent.jsx
import React from "react";
export default function YourComponent({ someProp }) {
return <div className="your-component">{someProp}</div>;
}
Register it in src/js/react-init.js
:
const COMPONENT_MAP = {
"hello-react": HelloReact,
"your-component": YourComponent, // Add your component here
};
Use it in your templates with data attributes:
<div
data-react-component="your-component"
data-some-prop="Hello World!"
class="mb-4"
></div>
All data attributes will be passed as props to your React component. For example:
data-some-prop="value"
becomes someProp="value"
data-user-id="123"
becomes userId="123"
You can also pass JSON data:
<div
data-react-component="your-component"
data-config='<?php echo json_encode([
"apiUrl" => rest_url('wp/v2/posts'),
"nonce" => wp_create_nonce('wp_rest'),
]); ?>'
></div>
For TypeScript users, define your props interface:
interface YourComponentProps {
someProp: string;
config?: {
apiUrl: string;
nonce: string;
};
}
export default function YourComponent({
someProp,
config,
}: YourComponentProps) {
// ...
}
src/css/style.css
- Main stylesheetsrc/css/_navigation.css
- Navigation stylessrc/css/_accessibility.css
- Accessibility stylessrc/css/_alignments.css
- WordPress alignment stylesMIT License