A WordPress plugin demonstrating how to integrate React applications within the WordPress admin interface using modern development tools and WordPress Scripts.
This plugin creates a custom admin page in WordPress and renders a React-based dashboard. It serves as a boilerplate/example for developers who want to build modern, interactive admin interfaces using React within WordPress.
- ✨ React 18+ integration with WordPress admin
- 🎨 WordPress Components (@wordpress/components)
- 🌐 WordPress i18n support for translations
- ⚡ Modern build setup using @wordpress/scripts
- 🔧 Hot reload development with
wp-scripts start - 📦 Production-ready build system
- Node.js: >= 20.10.0
- npm: >= 10.2.3
- WordPress: 5.0 or higher
- PHP: 7.4 or higher
-
Clone or download this repository into your WordPress plugins directory:
cd wp-content/plugins/ git clone [repository-url] react-in-wordpress-admin -
Navigate to the plugin directory:
cd react-in-wordpress-admin -
Install dependencies:
npm install
-
Build the plugin:
npm run build
-
Activate the plugin through the WordPress admin interface
npm start- Starts the development server with hot reloadnpm run build- Creates a production buildnpm run format- Formats code using WordPress standardsnpm run lint:js- Lints JavaScript filesnpm run lint:css- Lints CSS/SCSS files
-
Start the development server:
npm start
-
Make changes to files in the
src/directory -
Changes will automatically rebuild and reload
-
Build for production before deployment:
npm run build
react-in-wordpress-admin/
├── build/ # Compiled production files (auto-generated)
├── includes/ # PHP includes
│ └── admin.php # Admin menu and script enqueuing
├── src/ # Source files
│ └── dashboard/ # Dashboard React component
│ ├── Dashboard.js
│ └── index.js
├── test.php # Main plugin file
├── package.json # Node.js dependencies and scripts
├── webpack.config.js # Custom webpack configuration
└── Readme.md # This file
- Plugin Registration: The main plugin file (
test.php) registers the plugin with WordPress - Admin Menu: Creates a new menu item "Test Plugin" in the WordPress admin sidebar
- React Mounting: When the admin page loads, it:
- Enqueues the compiled JavaScript bundle
- Creates a React root element in the
.test-plugin-wrapdiv - Renders the Dashboard component
Edit includes/admin.php:
add_menu_page(
'Test Plugin Settings',
'Test Plugin',
'manage_options',
'test-plugin',
'test_plugin_settings_page',
'dashicons-admin-generic' // Change this to any dashicon
);- Create your component in
src/dashboard/ - Import it into
Dashboard.js - Run
npm startto see changes live
This plugin includes @wordpress/components. You can use any component:
import { Button, Panel, PanelBody, TextControl } from '@wordpress/components';The plugin is translation-ready using WordPress i18n:
import { __ } from '@wordpress/i18n';
// In your component
<h1>{ __( 'Your text here', 'test-plugin' ) }</h1>- Clear the
build/directory and runnpm run buildagain - Make sure
npm startis running during development
- Check browser console for errors
- Verify the build files exist in the
build/directory - Ensure the plugin is activated
- The admin page requires
manage_optionscapability - Make sure you're logged in as an administrator
Contributions are welcome! Please feel free to submit a Pull Request.
This plugin is licensed under the GPL-3.0-or-later license.
Iqbal Hossain
- Initial release
- React dashboard integration
- WordPress Scripts build system
- Basic admin interface