0

When creating a post using the WordPress REST API, should the post body content include HTML or should the post body content be written in Markdown language? Or can it be either?

I'm looking to include simple HTML such as links, formatting (<strong> tags) and possibly images (hosted elsewhere, like for example <img alt="Test example image" src="https://via.placeholder.com/150">).

I've seen many examples just using plain text strings and I'd like to know how to tell the WordPress API that I want to create a new post with HTML content in the post body.

Please could someone advise and offer some clarity?

I've seen someone else have difficulty when using HTML for images and so I'm not sure - Create post using rest api with html content

If you need more information from me to best answer this please do let me know.

Really hope you can help! Thank you.

1 Answer 1

1

WordPress doesn't support Markdown without a plugin. The content should be HTML.

3
  • Thank you. So in theory the following code should work ok? $api_response = wp_remote_post( 'http://example.com/apiwp/wp-json/wp/v2/posts', array( 'headers' => array( 'Authorization' => 'Basic ' . base64_encode( 'admin:xxxx' ) ), 'body' => array( 'title' => $title, 'content' => "<p><a href=\"https://www.google.com\">Here is a link to Google</a></p>", 'status' => 'publish', 'format' => 'standard' ) ) );
    – neo.vovk
    Commented May 18, 2020 at 12:02
  • Seems ok, but basic authentication is not supported without a plugin. You should just try it. Commented May 18, 2020 at 13:08
  • Yeah, I just wanted to run it passed someone before trying. Thank you so much @Jacob
    – neo.vovk
    Commented May 18, 2020 at 13:20

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.