I created a custom route with the wordpress API which allows me to retrieve the html content of the post When editing a post, I added an "Export to html" link with the download attribute

echo "<a href='".get_bloginfo('url')."/wp-json/export/post/".$post->ID."' class='button-primary' download>Exporter l'article</a>";

But when I click on the link I get a .json file

How to transform this .json into .html before downloading the file? My client will use this html export to import it into another site (not a wordpress site)


  • 2
    Maybe you can use the rest_pre_serve_request hook - see my answer here for an example.
    – Sally CJ
    Dec 5 '20 at 16:00
  • 1
    Thank you very much, you saved me, it works ! Dec 9 '20 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.