Everything to get a basic React app displaying within any WordPress page using a shortcode. Screenshot below.
- Install WordPress locally (I suggest using
valet
to easily create a localwordpress-plugin.test
domain) cd /path/to/wordpress/wp-content/plugins/
git clone [email protected]:dtbaker/react-wordpress-plugin.git
cd /path/to/wordpress/wp-content/plugins/react-wordpress-plugin/
yarn development
- Login to
wordpress-plugin.test/wp-admin/
- Go to Plugins and activate the Sample Plugin
- Go to
Pages
>Create New
and make a new page containing the content[display_react_app_here]
. This WordPress shortcode will render the react code and mount it to this location.
yarn eslint
( oryarn eslint --fix
)yarn sass-lint
yarn production
It should look like this after you add the shortcode to a page:
render() {
const { meow } = this.state
return (
<div className={styles.wrap}>
<div>Hey I am react! Current state is: {meow}</div>
<div>
<button
type="button"
onClick={() => {
this.setState({ meow: meow === "foo" ? "bar" : "foo" })
}}>
Change State
</button>
</div>
</div>
)
}
- lots. but this works fine.