3

I have a basic wordpress site at the moment, I would like to use a basic react frontend to display articles in my blog.

Can anyone tell me how I can hook the back end up to react?

Thanks

1 Answer 1

3

You would have to build a rest API within your wordpress site, you would then make calls to the rest api from your react app. Check here:

http://v2.wp-api.org/

A very simple example from the above link:

<?php
add_action( 'rest_api_init', function () {
    register_rest_route( 'route', '/author/(?P<id>\d+)', array(
        'methods' => 'GET',
        'callback' => 'my_awesome_func',
    ) );
} );

So basically you'd be able to simply integrate the rest api into your existing wordpress functions!

On your react site you'd simple use a fetch or ajax to grab the data! Checkout the fetch api here:

https://github.com/github/fetch

You could follow a tutorial, such as this one:

https://lamosty.com/2015/09/07/react-single-page-wordpress-rest-api-theme-tutorial/

Sign up to request clarification or add additional context in comments.

1 Comment

Latest WP versions have a REST API built in, no need for a plugin -- developer.wordpress.com/docs/api

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.